1. 程式人生 > >PHP預處理 CURD

PHP預處理 CURD

click 保存 result view ide color sql http use

一、數據庫連接方式,

  

二、預處理後的返回

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