2009-12-29 300 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行缺少分号。