1
我是一個初學php-mySQL的人。我的代碼如下 -mysql_error()不打印錯誤
<?php
echo "test_script running!!<br/>";
$con=mysqli_connect("localhost","root","root","netHealth");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
else
echo "Connection established <br/>" ;
for($i=1;$x<4;$i+=1)
{
$sql1="INSERT INTO `netHealth`.`role_perm` (`role_id` ,`perm_id`) VALUES ($i, '1')";
$sql2="INSERT INTO `netHealth`.`role_perm` (`role_id` ,`perm_id`) VALUES ($i, $i+1)";
try {
$res1=mysqli_query($con,$sql1);
if (!$res1) throw new Exception("mysql Error");
} catch(Exception $e) {
echo $e->getMessage();
echo mysql_error();
break;
}
try {
$res2=mysqli_query($con,$sql2);
if (!$res2) throw new Exception("mysql Error");
} catch(Exception $e) {
echo $e->getMessage();
echo mysql_error();
break;
}
}
?>
錯誤很好,因爲列表項無法在role_perm表中複製。但是mysql_error()函數不返回任何錯誤描述。輸出如下 -
test_script running!!
Connection established
mysql Error
這裏有什麼問題?