4

I have a shell script that calls a php script to insert records in database after parsing text file. When it calls the PHP script I get errors that it cannot find mysqli:

PHP Fatal error:  Class 'mysqli' not found in /path/to/php/file.php on line 5

This failed in local on Macbook Pro with Nginx and PHP-FPM and Mysql 5.5.x and after I added the socket param to mysqli call, it worked in local. This worked with local db!

$mysqli = new mysqli("localhost", "user", "pass", "mydb", 3306, "/tmp/mysql.sock");

I deployed to Linux server (CentOS6 that has 'yum install php' with PHP 5.3.x) installed. I changed the connection to a remote db server so dropped the "/tmp/mysql.sock" because db not running on this server.

Shell script calling php to execute script:

php -c "/etc/php.ini" -f "/path/to/php/file.php"

Given I am not running mysql locally, how do I get it to recognize the mysqli lib and execute. It's on CentOS6. I even tried adding mysqli.so to php.ini file and got following error:

[mike@app2 myapp]# php -version
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/mysqli.so' - /usr/lib64/php/modules/mysqli.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP 5.3.3 (cli) (built: Feb  2 2012 23:47:49) 
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

Thanks for any help resolving this. Normally I'd use mysql(query) but need mysqli() for some prepared statements and other bits in the script.

1
  • 1
    Don't normally use mysql_*. Commented Jul 20, 2012 at 19:00

2 Answers 2

8

I found that mysqli was not installed with PHP and ran the following command:

>php -i

This returned the phpinfo() and found no mention of mysqli. I then ran the 'yum' command to install php-mysqli:

>yum install php-mysqli

After this the script worked successfully. Hope this helps others that might run into similar.

Sign up to request clarification or add additional context in comments.

Comments

1

PHP CLI will have its own environmental setup from that used by the webserver. If you don't have mysqli available in the CLI environment that would cause this issue.

4 Comments

Thanks Mike. Any idea how to add to the CLI environment?
@MikeS. Did you find out how to add to the CLI environment? I'm going through this same challenge now.
@arya look at accepted answer. Depending on your OS you may need to use different package installer like aptitude
@MikeBrant: I installed mysqli on Ubuntu LTS 14.04 OS using: sudo apt-get install php5-mysql. The same challenge remains.

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.