I've got a basic php script that runs perfect in a browser. I want to run this same php script at the shell command line (Freebsd 8.0), but I'm having troubles when the script tries to connect to the database using "mysql_query"....the rest of the script runs fine, but the connection to the database just doesn't happen.
我有一个基本的PHP脚本,在浏览器中运行完美。我想在shell命令行(Freebsd 8.0)上运行相同的php脚本,但是当脚本尝试使用“mysql_query”连接到数据库时我遇到了麻烦......其余的脚本运行正常但是不会发生与数据库的连接。
I verified that the php.ini in phpinfo() is what I am using, but still nothing.
我验证了phpinfo()中的php.ini是我正在使用的,但仍然没有。
Here's the command:
这是命令:
php -c /usr/local/etc/php.ini /data/phpscript.php
The ouptput should be an array of data, which i verified the SQL with in phpmyadmin and results are there, instead it returns nothing and I don't get any error messages in the log files.
ouptput应该是一个数据数组,我在phpmyadmin中验证了SQL,结果在那里,而不返回任何内容,我没有在日志文件中收到任何错误消息。
Any ideas whats going on here? I've always used the browser to run my php stuff, but this time I need to put it into a crontab and run it from the server directly on a schedule.
有什么想法在这里发生?我一直用浏览器运行我的php东西,但这次我需要将它放入crontab并直接按计划从服务器运行。
Thanks in advance
提前致谢
2 个解决方案
#1
1
echo the error code and error string the mysqli function can give you after each run.
Also check that your php.ini does not shut down your error messages (so you do not see anything as there is no Apache error log in CLI).
This two steps should give you the answer.
回显每次运行后mysqli函数可以给你的错误代码和错误字符串。还要检查你的php.ini是否没有关闭你的错误消息(所以你没有看到任何东西,因为CLI中没有Apache错误日志)。这两个步骤应该给你答案。
#2
1
setsebool -P httpd_can_network_connect=1
#1
1
echo the error code and error string the mysqli function can give you after each run.
Also check that your php.ini does not shut down your error messages (so you do not see anything as there is no Apache error log in CLI).
This two steps should give you the answer.
回显每次运行后mysqli函数可以给你的错误代码和错误字符串。还要检查你的php.ini是否没有关闭你的错误消息(所以你没有看到任何东西,因为CLI中没有Apache错误日志)。这两个步骤应该给你答案。
#2
1