我有一个 shell 脚本,它在解析文本文件后调用 php 脚本在数据库中插入记录.当它调用 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 上本地失败,在我将套接字参数添加到 mysqli 调用后,它在本地工作.这适用于本地数据库!
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 服务器(CentOS6 安装了 'yum install php' 和 PHP 5.3.x).我更改了与远程 db 服务器的连接,因此删除了/tmp/mysql.sock",因为 db 未在此服务器上运行.
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脚本调用php执行脚本:
Shell script calling php to execute script:
php -c "/etc/php.ini" -f "/path/to/php/file.php"
鉴于我没有在本地运行 mysql,我如何让它识别 mysqli lib 并执行.它在 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() 用于脚本中的一些准备好的语句和其他位.
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.
发现mysqli没有安装php,运行如下命令:
I found that mysqli was not installed with PHP and ran the following command:
>php -i
这返回了 phpinfo() 并且发现没有提到 mysqli.然后我运行 '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
在此之后脚本成功运行.希望这对可能遇到类似情况的其他人有所帮助.
After this the script worked successfully. Hope this helps others that might run into similar.
这篇关于命令行 php mysqli 失败但通过 Web 服务器工作并在本地工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!