码迷,mamicode.com
首页 > Web开发 > 详细

PHP预处理 CURD

时间:2017-07-24 10:09:54      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:host   print   closed   password   logs   oca   statement   cli   select   

一、数据库连接方式,

  

二、预处理后的返回

  参考:http://www.php.net/manual/en/class.mysqli-stmt.php

  注意。select查询语句后要保存查询结果。然后才有 num_rows;

  

技术分享
<?php
/* Open a connection */
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$query = "SELECT Name, CountryCode FROM City ORDER BY Name LIMIT 20";
if ($stmt = $mysqli->prepare($query)) {

    /* execute query */
    $stmt->execute();

    /* store result */
    $stmt->store_result();

    printf("Number of rows: %d.\n", $stmt->num_rows);

    /* close statement */
    $stmt->close();
}

/* close connection */
$mysqli->close();
?>
View Code

 

PHP预处理 CURD

标签:host   print   closed   password   logs   oca   statement   cli   select   

原文地址:http://www.cnblogs.com/mxh1099/p/7227119.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!