PHP預處理 CURD
阿新 • • 發佈:2017-07-24
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_errorView Code()); 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(); ?>
PHP預處理 CURD