您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息

mysqli 为什么不提示字段异常

2024/4/26 8:07:25发布5次查看
mysqli 为什么不提示字段错误
本帖最后由 goimt 于 2015-08-29 21:48:01 编辑 注意是用mysqli,不是mysql (mysql是有提示的)
如:
query(update {$tpre}member set ttid='2000' where userid123='10000');
没有userid123这个字段,执行时,没有更新但也没有提示错误
怎么能让它提示 没有这个字段的 错误
用mysql5.7,php5.6
------解决思路----------------------
面向对象风格的错误抛出:
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查询错误抛出
}
?>

面向过程风格的错误抛出:

------解决思路----------------------
$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 操作所影响的记录行数
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录