最新的Web开发教程
 

PHP mysqli_stmt_init() Function

<PHP库MySQLi参考

初始化语句,并返回一个对象与使用mysqli_stmt_prepare()

<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno())
  {
  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+

<PHP库MySQLi参考