編輯一個php連接nysql的網頁 包括下列四種情況
假設web server與mysql都在同一部server
連線位置用 localhost即可
假設帳號為bbb
密碼為ccc
複製程式
<?
echo "===================完整無誤的連接=================<br>";
mysql_connect("localhost","bbb","ccc");
echo "===================連接server位置錯誤=================<br>";
mysql_connect("111.111.111.111","bbb","ccc");
echo "===================server與user正確,但passwd錯誤=================<br>";
mysql_connect("localhost","bbb","xxx");
echo "===================server正確,但user,passwd錯誤=================<br>";
mysql_connect("localhost","aaa","aaa");
?>
連上測試網頁後將看到
===================完整無誤的連接=================
(連線成功無任何訊息)
===================連接server位置錯誤=================
Warning: mysql_connect(): Can't connect to MySQL server on 飇.111.111.111' (4) in /srv/www/htdocs/phptest/php_mysql.php on line 5
===================server與user正確,但passwd錯誤=================
Warning: mysql_connect(): Access denied for user: 'bbb@localhost' (Using password: YES) in /srv/www/htdocs/phptest/php_mysql.php on line 7
===================server正確,但user,passwd錯誤=================
Warning: mysql_connect(): Access denied for user: 'aaa@localhost' (Using password: YES) in /srv/www/htdocs/phptest/php_mysql.php on line 9