注意是用mysqli,不是mysql (mysql是有提示的)
如:
query("update {$tpre}member set ttid='2000' where userid123='10000'");
没有userid123这个字段,执行时,没有更新但也没有提示错误
怎么能让它提示 没有这个字段的 错误
用MYSQL5.7,php5.6
------解决思路----------------------
面向对象风格的错误抛出:
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* check connection */
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error); //mysql连接错误抛出
exit();
}
if (!$mysqli->query("SET a=1")) {
printf("Errormessage: %s\n", $mysqli->error); //mysql查询错误抛出
}
?>
面向过程风格的错误抛出:
<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
if (!mysqli_query($link, "SET a=1")) {
printf("Errormessage: %s\n", mysqli_error($link));
}
?>
------解决思路----------------------
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
// $mysqli->affected_rows 取得前一次 MySQLI 操作所影响的记录行数
$mysqli->query("update {$tpre}member set ttid='2000' where userid123='10000'");
printf("Affected rows (UPDATE): %d\n", $mysqli->affected_rows);
$mysqli->affected_rows 在mysqli可以取得前一次 MySQLI 操作所影响的记录行数