标签:错误 bin 大数 ini ble cal bool integer prepare
MySQLi预处理涉及到以下几个函数:
mysqli_stmt mysqli_prepare ( mysqli $link , string $query ) bool mysqli_stmt_bind_param ( mysqli_stmt $stmt , string $types , mixed &$var1 [, mixed &$... ] ) bool mysqli_stmt_execute ( mysqli_stmt $stmt ) bool mysqli_stmt_close ( mysqli_stmt $stmt ) mixed mysqli_query ( mysqli $link , string $query) bool mysqli_set_charset ( mysqli $link , string $charset )
具体的示例代码如下:
<?php
$conn=mysqli_connect("localhost","root","root","test");
//设置字符集
mysqli_set_charset($conn,"utf8");
//预处理,注意返回的类型是mysqli_stmt
$stmt=mysqli_prepare($conn,"insert into aaa values (?,?)");
// 绑定参数,第二个参数,请看下文注解
// 注意,在$id,$name等变量的位置,不能出现常亮
// mysqli_stmt_bind_param($stmt,"is",5,‘aaaaa‘);写法是错误的
mysqli_stmt_bind_param($stmt,"is",$id,$name);
// 参数赋值
$id="99";$name="xxxxxx";
//执行预处理
mysqli_stmt_execute($stmt);
//关闭预处理,
//注意关闭的不是数据库连接,而是“预处理”
mysqli_stmt_close($stmt);
//关闭数据库连接
mysqli_close($conn);
?>
这里注意绑定参数的时候,
bool mysqli_stmt_bind_param ( mysqli_stmt $stmt , string $types , mixed &$var1 [, mixed &$... ] )
第二个参数是类型(type),类型有4个类型,分别是:
i(整型integer)、
d(双精度浮点数double)、
s(字符串string)、
b(二进制大数据块blob)
每一个类型,即每个字母(i/d/s/b)对应一个参数,每个参数的位置所对应的类型要正确,顺序别颠倒
标签:错误 bin 大数 ini ble cal bool integer prepare
原文地址:http://www.cnblogs.com/-beyond/p/7577155.html