一、数据库连接方式,
二、预处理后的返回
参考:http://www.php.net/manual/en/class.mysqli-stmt.php
注意。select查询语句后要保存查询结果。然后才有 num_rows;
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<?php /* Open a connection */ $mysqli = new mysqli("localhost", "my_user", "my_password", "world"); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s ", 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. ", $stmt->num_rows); /* close statement */ $stmt->close(); } /* close connection */ $mysqli->close(); ?>