开发者

php cannot connect to DB when execute in terminal [closed]

开发者 https://www.devze.com 2023-03-20 05:27 出处:网络
Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed. This question is off-topic. It is not currently accepting answers.

Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 11 years ago.

开发者_如何学C Improve this question

im connecting my php script with this simple code:

mysql_connect("localhost", "admin", "1admin") or die("DB Failed"); mysql_select_db("test") or die(mysql_error());

but when execute in terminal, DB failed. however this works on browser.


PHP from commandline usually uses a different php.ini from php-cli. If your are on a linux server - look into /etc/php/cli/php.ini (Or something like that...)

Check if mysql is enabled in this php.ini


Try

mysql_connect(...) or die(mysql_error());

Simply outputting "db failed" is useless for diagnost purposes, especially when MySQL will tell you exactly what's wrong with mysql_error().

0

精彩评论

暂无评论...
验证码 换一张
取 消