PHP预处理 CURD

一、数据库连接方式,

  

二、预处理后的返回

  参考: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

 

posted @ 2017-07-24 08:58  半天的半天  阅读(144)  评论(0编辑  收藏  举报