Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
开发者_如何学C Improve this questionim 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().
精彩评论