PHP 教程 PHP 表单 PHP 高级教程 PHP 数据库 PHP XML PHP 与 AJAX PHP 参考手册

发布于 2016-11-18 14:46:13 | 52 次阅读 | 评论: 0 | 来源: 网络整理

实例

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

 <?php
 $con=mysqli_connect("localhost","my_user","my_password","my_db");
 // Check connection
 if (mysqli_connect_errno($con))
 {
 echo "Failed to connect to MySQL: " . mysqli_connect_error();
 }

$city="Sandnes";

// Create a prepared statement
 $stmt=mysqli_stmt_init($con);

if (mysqli_stmt_prepare($stmt,"SELECT District FROM City WHERE Name=?"))
 {

 // Bind parameters
 mysqli_stmt_bind_param($stmt,"s",$city);

 // Execute query
 mysqli_stmt_execute($stmt);

 // Bind result variables
 mysqli_stmt_bind_result($stmt,$district);

 // Fetch value
 mysqli_stmt_fetch($stmt);

 printf("%s is in district %s",$city,$district);

 // Close statement
 mysqli_stmt_close($stmt);
 }

mysqli_close($con);
 ?> 

定义和用法

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


语法

 mysqli_stmt_init(connection);

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

技术细节

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


最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务