我不断收到错误消息:
致命错误:在第46行的C:\ wamp \ www \ Website \ index.php中的非对象上调用成员函数execute()
以下是我的代码。怎么可能出错?我现在只使用股票root帐户。
<?php
$dbserver="localhost";
$username="root";
$password="";
$connection=mysql_connect("$dbserver","$username","$password")or die("could not connect to the server");
//execute an SQL statement and return a recordset
$rs = $connection->execute("SELECT product_name FROM products");
$num_columns = $rs->Fields->Count();
echo "<table border='1'>";
echo "<tr><th>Name</th></tr>";
while (!$rs->EOF) //looping through the recordset (until End Of File)
{
echo "<tr>";
for ($i=0; $i < $num_columns; $i++) {
echo "<td><a href=\"product.php?id=" . $rs->Fields('id').value . "\">" . $rs->Fields($i)->value . "</a></td>";
}
echo "</tr>";
$rs->MoveNext();
}
echo "</table>";
//close the recordset and the database connection
$rs->close();
$rs = null;
$conn->close();
$conn = null;
?>