PHP mysqli_stmt_init() 函数

PHP 教程 · 2019-01-28 12:58:56

初始化声明并返回 mysqli_stmt_prepare() 使用的对象:

<?php 
// 假定数据库用户名:root,密码:123456,数据库:CODERCTO 
$con=mysqli_connect("localhost","root","123456","CODERCTO"); 
if (mysqli_connect_errno($con)) 
{ 
    echo "连接 MySQL 失败: " . mysqli_connect_error(); 
} 
// 修改数据库连接字符集为 utf8
mysqli_set_charset($con,"utf8");

$country="CN";

// 创建预处理语句
$stmt=mysqli_stmt_init($con);

if (mysqli_stmt_prepare($stmt,"SELECT name FROM websites WHERE country=?"))
{
    
    // 绑定参数
    mysqli_stmt_bind_param($stmt,"s",$country);
    
    // 执行查询
    mysqli_stmt_execute($stmt);
    
    // 绑定结果变量
    mysqli_stmt_bind_result($stmt,$name);
    
    // 获取值
    mysqli_stmt_fetch($stmt);
    
    printf("%s 国家的网站为:%s",$country,$name);
    
    // 关闭预处理语句
    mysqli_stmt_close($stmt);
}

mysqli_close($con);
?>

定义和用法

mysqli_stmt_init() 函数初始化声明并返回 mysqli_stmt_prepare() 使用的对象。

语法

mysqli_stmt_init(connection);

参数 描述
connection 必需。规定要使用的 MySQL 连接。

技术细节

返回值: 返回一个对象。
PHP 版本: 5+

点击查看所有 PHP 教程 文章: https://codercto.com/courses/l/5.html

查看所有标签

Computers and Intractability

Computers and Intractability

M R Garey、D S Johnson / W. H. Freeman / 1979-4-26 / GBP 53.99

This book's introduction features a humorous story of a man with a line of people behind him, who explains to his boss, "I can't find an efficient algorithm, but neither can all these famous people." ......一起来看看 《Computers and Intractability》 这本书的介绍吧!

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试