PHP mysqli_stmt_bind_param MySQLi 函数
定义和用法
mysqli_stmt_bind_param - 将变量绑定到准备好的语句作为参数
版本支持
| PHP4 | PHP5 | PHP7 |
|---|---|---|
| 不支持 | 支持 | 支持 |
语法
mysqli_stmt_bind_param ( mysqli_stmt $stmt , string $types , mixed &$var1 [, mixed &$... ] ) |
在传递给 mysqli_prepare() 的SQL语句中为参数标记绑定变量。
注意: 如果变量的数据大小超过最大值。 如果允许数据包大小(max_allowed_packet),则必须在类型中指定b并使用mysqli_stmt_send_long_data()以数据包形式发送数据。
注意: 将mysqli_stmt_bind_param()与call_user_func_array()结合使用时必须小心。请注意,mysqli_stmt_bind_param()要求参数通过引用传递,而call_user_func_array()可以接受可以表示引用或值的变量列表作为参数。
参数
| 参数 | 必需的 | 描述 |
|---|---|---|
| stmt | 是 | 由 mysqli_stmt_init() 返回的 statement 标识。 |
| types | 是 | 一个包含一个或多个字符的字符串,这些字符指定相应绑定变量的类型:
|
| var1 | 是 | 变量的数量和字符串类型的长度必须与语句中的参数匹配。 |
| ... | 否,取决types,是否有变量需要绑定 | 更多变量 |
返回值
成功时返回 TRUE, 或者在失败时返回 FALSE。
示例
<?php$link = mysqli_connect('localhost', 'my_user', 'my_password', 'world');/* check connection */if (!$link) { printf("Connect failed: %s\n", mysqli_connect_error()); exit();}$stmt = mysqli_prepare($link, "INSERT INTO CountryLanguage VALUES (?, ?, ?, ?)");mysqli_stmt_bind_param($stmt, 'sssd', $code, $language, $official, $percent);$code = 'DEU';$language = 'Bavarian';$official = "F";$percent = 11.2;/* execute prepared statement */mysqli_stmt_execute($stmt);printf("%d Row inserted.\n", mysqli_stmt_affected_rows($stmt));/* close statement and connection */mysqli_stmt_close($stmt);/* Clean up table CountryLanguage */mysqli_query($link, "DELETE FROM CountryLanguage WHERE Language='Bavarian'");printf("%d Row deleted.\n", mysqli_affected_rows($link));/* close connection */mysqli_close($link); |
本文来自学习小花,作者:aixuexi666888,转载请注明原文链接:https://www.cnblogs.com/aixuexi666888/p/15542467.html

浙公网安备 33010602011771号