Home > Backend Development > PHP Tutorial > mysqli 为什么不提示字段异常

mysqli 为什么不提示字段异常

WBOY
Release: 2016-06-13 12:24:20
Original
1007 people have browsed it

mysqli 为什么不提示字段错误

本帖最后由 goimt 于 2015-08-29 21:48:01 编辑 注意是用mysqli,不是mysql (mysql是有提示的)
如:
query("update {$tpre}member set ttid='2000'  where userid123='10000'"); 
Copy after login


没有userid123这个字段,执行时,没有更新但也没有提示错误
怎么能让它提示 没有这个字段的 错误



用MYSQL5.7,php5.6
------解决思路----------------------
面向对象风格的错误抛出:
<br /><?php<br />$mysqli = new mysqli("localhost", "my_user", "my_password", "world");<br /><br />/* check connection */<br />if ($mysqli->connect_errno) {<br />    printf("Connect failed: %s\n", $mysqli->connect_error); //mysql连接错误抛出<br />    exit();<br />}<br /><br />if (!$mysqli->query("SET a=1")) {<br />    printf("Errormessage: %s\n", $mysqli->error); //mysql查询错误抛出<br />}<br />?><br />
Copy after login


面向过程风格的错误抛出:
<br /><?php<br />$link = mysqli_connect("localhost", "my_user", "my_password", "world");<br /><br />/* check connection */<br />if (mysqli_connect_errno()) {<br />    printf("Connect failed: %s\n", mysqli_connect_error());<br />    exit();<br />}<br /><br />if (!mysqli_query($link, "SET a=1")) {<br />    printf("Errormessage: %s\n", mysqli_error($link));<br />}<br /><br />?><br />
Copy after login

------解决思路----------------------
<br />$mysqli = new mysqli("localhost", "my_user", "my_password", "world");<br /><br />/* check connection */<br />if (mysqli_connect_errno()) {<br />    printf("Connect failed: %s\n", mysqli_connect_error());<br />    exit();<br />}<br /><br />//  $mysqli->affected_rows 取得前一次 MySQLI 操作所影响的记录行数<br />$mysqli->query("update {$tpre}member set ttid='2000'  where userid123='10000'");<br />printf("Affected rows (UPDATE): %d\n", $mysqli->affected_rows);<br />
Copy after login

  $mysqli->affected_rows 在mysqli可以取得前一次 MySQLI 操作所影响的记录行数
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template