我是面向对象的 php 新手。我明白这条线是什么意思
$result = $db->query($query);
这里 $db 是引用类 mysqli 实例的对象。正确的?
但是我不理解
$total_num_rows = $result->num_rows;
和
while($row = $result->fetch_array())
我知道他们做什么。但是我无法理解为什么它是用 $result->... 写的
整个脚本:
<?php
$host = "localhost";
$username = "root";
$password = "";
$dbname = "compdb";
@ $db = new mysqli($host, $username, $password, $dbname);
if(mysqli_connect_errno())
{
die("Connection could not be established");
}
$query = "SELECT company_id FROM company_basic_details WHERE company_name = 'ABC'";
$result = $db->query($query);
$total_num_rows = $result->num_rows;
echo "The Results Are : <br>";
while($row = $result->fetch_array())
{
echo $row['company_id'];
}
?>