开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜