1

I've installed various PHP packages to be able to use PHP with Apache but also in the commandline. From both I need to be able to connect to MySQL databases. Pretty simple right? That's what I thought but with php-cli I receive following error:

Fatal error: Call to undefined function mysql_pconnect()

I have tried starting from scratch by removing all depending packages and configuration like this:

sudo apt-get --purge remove php5 libapache2-mod-php5 php5-cli php5-mysql

Then I've run following command to install the packages:

sudo apt-get install php5 libapache2-mod-php5 php5-cli php5-mysql

Then I've found out which php.ini the cli uses like that:

php -r "phpinfo();" | grep php.ini

Which gives me this:

Configuration File (php.ini) Path => /etc/php5/cli/php.ini

Then i've uncommented 'mysql.so' in the extensions section but when i do and run following command it says:

PHP Warning:  Module 'mysql' already loaded in Unknown on line 0

So for some reason he thinks it is already loaded, but with or without the 'mysql.so' enabled the php cli does not find the 'mysql_pconnect' function.

I know there's a sections to enable persistent connections, it on by default and the standard function 'mysql_connect' is also not available.

What am I missing? Thanks!

UPDATE:

As suggested by Bart S. 'php -r "phpinfo();" | grep mysql':

MYSQL_SOCKET => /var/run/mysqld/mysqld.sock
MYSQL_INCLUDE => -I/usr/include/mysql
MYSQL_LIBS => -L/usr/lib -lmysqlclient
mysql.allow_persistent => On => On
... and more

From Jaka Jančar. 'php -v' shows:

PHP 5.1.2 (cli) (built: Feb 11 2009 19:55:22)

And from php interactive mode 'php -r 'var_dump(extension_loaded("mysql"));' gives nothing!

6
  • Does it say it list the MySQL modules when you execute phpinfo();? Commented Apr 8, 2009 at 8:42
  • @bart I've updated my question with some more info Commented Apr 8, 2009 at 8:51
  • Can you please do: php -v php -r 'var_dump(extension_loaded("mysql"));' Commented Apr 8, 2009 at 8:57
  • A newline missing after "php -v", of course. Commented Apr 8, 2009 at 8:58
  • @jaka Updated with your suggestion. var_dump returns nothing. txn. Commented Apr 8, 2009 at 9:06

3 Answers 3

1
php -i | grep mysql

The first line should contain:

Configure Command =>  '../configure' ... '--with-mysql=shared,/usr'

Also check

grep extension_dir /etc/php5/cli/php.ini

Should be something like: extension_dir = /usr/lib/php5/extensions Then check permissions of /usr/lib/php5/extensions/mysql.so and if it's properly linked:

ldd  /usr/lib/php5/extensions/mysql.so
Sign up to request clarification or add additional context in comments.

Comments

1

You cant use pconnect in CLI mode. You dont have a persistent process like the web server which can hold the open connection.

Comments

-1

Does pconnect in cli mode make sense? maybe this is "working as intended".

Note: Note, that these kind of links only work if you are using a module version of PHP. See the Persistent Database Connections section for more information.

https://www.php.net/mysql_pconnect

1 Comment

mysql_connect doesn't work either. And i would think mysql_pconnect should work, but idd it does not make sense, i'm using the sphyder search engine cli scripts. and i'm using it exactly like docs tell me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.