<?php
/*
$link = mysql_connect("127.0.0.1", "root", "123456");
mysql_select_db("book_sc", $link);
$result = mysql_query("SELECT * FROM books", $link);
$num_rows = mysql_num_rows($result);
echo "$num_rows 行\n";*/
$db = new mysqli('127.0.0.1', 'root', '123456', 'book_sc');
$result = $db->query("select * from books");
$row = $result->num_rows();
echo $row;
$result->close();
?>
$result->num_rows() 报错:Call to undefined method mysqli_result::num_rows()
解决方法:去掉$result->num_rows() 后面的括号
/*
$link = mysql_connect("127.0.0.1", "root", "123456");
mysql_select_db("book_sc", $link);
$result = mysql_query("SELECT * FROM books", $link);
$num_rows = mysql_num_rows($result);
echo "$num_rows 行\n";*/
$db = new mysqli('127.0.0.1', 'root', '123456', 'book_sc');
$result = $db->query("select * from books");
$row = $result->num_rows();
echo $row;
$result->close();
?>
$result->num_rows() 报错:Call to undefined method mysqli_result::num_rows()
解决方法:去掉$result->num_rows() 后面的括号