PHP MySQL连接错误
我试图通过以下代码通过PHP连接到MySQLPHP MySQL连接错误,php,mysql,Php,Mysql,我试图通过以下代码通过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_
<?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 = 'test_cemail@gmail.com' AND cbref = 'test_cbref'");
mysql_close($con);
?>
您是否在“pass”之后缺少分号?您在$pass
行中缺少分号。您缺少;在pass之后使用以下语法
$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());
只是一个提示,您可能需要设置错误报告(E_ALL);在php脚本的开头。这样,您将收到所有错误的通知。现在看起来你正在抑制一些错误。我从中找到了这篇文章。