<?php
2
3 $db = new mysqli("localhost","user","password","testdb");
4
5 if (mysqli_connect_errno()){
6 printf("Error:%s\n",mysqli_connect_error());
7 exit;
8 }
9 else {
10 if ($stmt = $db->prepare("select id,name,author,price from book where name like ?")){
11 //如上行,$stmt并没有实例化,但是为什么可以调用函数了?
12 $stmt->bind_param('s',$n);
13 $n = "%p%";
14
15 $stmt->execute();
16
17 $stmt->store_result();
18 $stmt->bind_result($id,$name,$author,$price);
19 while ($stmt->fetch()){
20 printf("%s:%s,%s,%s<br/>",$id,$name,$author,$price);
21 }
22 $stmt->close();
23 }
24
25 $db->close();
26 }
27 ?>
2
3 $db = new mysqli("localhost","user","password","testdb");
4
5 if (mysqli_connect_errno()){
6 printf("Error:%s\n",mysqli_connect_error());
7 exit;
8 }
9 else {
10 if ($stmt = $db->prepare("select id,name,author,price from book where name like ?")){
11 //如上行,$stmt并没有实例化,但是为什么可以调用函数了?
12 $stmt->bind_param('s',$n);
13 $n = "%p%";
14
15 $stmt->execute();
16
17 $stmt->store_result();
18 $stmt->bind_result($id,$name,$author,$price);
19 while ($stmt->fetch()){
20 printf("%s:%s,%s,%s<br/>",$id,$name,$author,$price);
21 }
22 $stmt->close();
23 }
24
25 $db->close();
26 }
27 ?>
解决方案 »
- 各位大大们,请教一段代码的详细注释或讲解,谢谢各位大大,高手们....
- ff转换的问题,高手帮下啊!!为何总无效!
- Windows 2003 Server IIS作服务器,进程中出现N多php.exe,造成死机
- 菜鸟有问题需要大家的帮助!!!急!!!
- mysql 存放二进制文件(pdf)用php怎么读取啊?
- 怎么写这个正则表达式??
- 正则表达式,求 <tr ...> </tr> 中的内容。
- 宇凡请进!!
- 怎么做一个更新时不会闪烁的聊天室?
- 如何在windows2000下安装,调试Mysql?请高手指点?
- php 文件下载 兼容safari
- 胜蓝博创创始人何韬“PHP+HTML5开发涂鸦爱情墙”公开课11月12日正式开课!速报名!
13 $n = "%p%";
14
15 $stmt->execute();
这里的代码是不是有问题应该是$db去调用方法才是吧。
原型:
mysqli_stmt mysqli::prepare ( string $query )mysqli::prepare 返回一个 mysqli_stmt 类型数据
而 mysqli_stmt 类型是一个对象,那么
$stmt = $db->prepare("select id,name,author,price from book where name like ?")
中的 $stmt 不就是个 mysqli_stmt 对象了吗?