問題描述
我有一個 shell 腳本,它調(diào)用一個 php 腳本在解析文本文件后在數(shù)據(jù)庫中插入記錄.當(dāng)它調(diào)用 PHP 腳本時,我收到找不到 mysqli 的錯誤:
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
這在使用 Nginx 和 PHP-FPM 以及 Mysql 5.5.x 的 Macbook Pro 本地失敗,在我將套接字參數(shù)添加到 mysqli 調(diào)用后,它在本地工作.這適用于本地數(shù)據(jù)庫!
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");
我部署到 Linux 服務(wù)器(安裝了yum install php"和 PHP 5.3.x 的 CentOS6).我更改了與遠(yuǎn)程數(shù)據(jù)庫服務(wù)器的連接,因此刪除了/tmp/mysql.sock",因為數(shù)據(jù)庫未在此服務(wù)器上運(yùn)行.
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腳本調(diào)用php執(zhí)行腳本:
Shell script calling php to execute script:
php -c "/etc/php.ini" -f "/path/to/php/file.php"
鑒于我沒有在本地運(yùn)行 mysql,如何讓它識別 mysqli 庫并執(zhí)行.它在 CentOS6 上.我什至嘗試將 mysqli.so 添加到 php.ini 文件并得到以下錯誤:
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
感謝您幫助解決此問題.通常我會使用 mysql(query) 但需要 mysqli() 來處理一些準(zhǔn)備好的語句和腳本中的其他位.
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.
推薦答案
發(fā)現(xiàn)mysqli沒有安裝php,運(yùn)行如下命令:
I found that mysqli was not installed with PHP and ran the following command:
>php -i
這返回了 phpinfo() 并沒有發(fā)現(xiàn) mysqli.然后我運(yùn)行'yum'命令來安裝php-mysqli:
This returned the phpinfo() and found no mention of mysqli. I then ran the 'yum' command to install php-mysqli:
>yum install php-mysqli
此后腳本成功運(yùn)行.希望這能幫助其他可能遇到類似問題的人.
After this the script worked successfully. Hope this helps others that might run into similar.
這篇關(guān)于命令行 php mysqli 失敗,但可通過 Web 服務(wù)器運(yùn)行并在本地運(yùn)行的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!