2009-12-29 120 views
0

我試圖通過PHP通過下面的代碼PHP,MySQL連接錯誤

<?php 

$dbhost = 'localhost'; 
$dbuser = 'root'; 
$pass = 'pass'; 


$con = mysql_connect($dbhost,$dbuser,$pass); 
if (!$con) 
    { 
    die('Could not connect: ' . mysql_error()); 
    } 

mysql_select_db("test", $con); 

mysql_query("UPDATE cbdb SET fax = '36160' 
WHERE cemail = '[email protected]' AND cbref = 'test_cbref'"); 

mysql_close($con); 
?> 

連接到MySQL,但即使顯示MySQL連接錯誤的錯誤時顯示。

+2

只是一個提示,你可能想要設置error_reporting(E_ALL);在你的PHP腳本的開始。這樣你會收到所有錯誤的通知。現在看起來你正在壓制一些錯誤。 – 2009-12-29 04:31:31

+0

我從[致力於關閉錯字問題](http://meta.stackexchange.com/questions/167342/close-all-the-typo-questions#comment498341_168974)中找到了這篇文章。 – Pops 2013-02-25 18:06:55

回答

1

你缺少;通過並使用下面的語法

$db_host=" "; //the host name of the sql server (if you do not know, leave as localhost. usually works) 
    $db_name=" "; //the name of the database 
    $db_user=" "; //the username that is associated with the database 
    $db_pass=" "; //the password for the username 

    $dbc=mysql_connect($db_host,$db_user,$db_pass) OR DIE (mysql_error()); 
    $dbs=mysql_select_db($db_name) OR DIE (mysql_error()); 
5

「傳球」後你是否遺失了一個分號?

1

你在$pass行缺少分號。