友達がphpを変更したので、mysqliを使用していますが、コードを少し変更した後も次のように表示されます。致命的なエラー:C:\ wamp \ www \ web2\database.phpの未定義のメソッドmysqli::fetch_object()を呼び出す44行目
<?php
class Database
{
public $server = "localhost";
public $database = "database";
public $user = "root";
public $password = "";
public $row;
public $result;
public $sqlExtra = " ORDER BY firstname ASC";
public $dbLocalHost;
//call connection method upon constructing
public function __construct(){
$this->createConnection();
}
//connection to the database
public function createConnection()
{
$this->dbLocalhost = new mysqli($this->server, $this->user, $this->password, $this->database)
or die("could not connect:");
//mysql_select_db($this->database)
//
// or die("Could not find the database: ".mysql_error());
}
//execute query string
public function query($queryString)
{
$result = $this->dbLocalhost->query($queryString);
while($row = $this->dbLocalhost->fetch_object($result))
{
echo "<tr><td>".$row[0]."</td><td>".$row[1]."</td><td>".$row[2]."</td></tr>";
}
}
public function newRecord($fname, $lname)
{
$firstname = $fname;
$lastname = $lname;
$this->emptyCheck($firstname, $lastname);
$this->insert($firstname, $lastname);
}
function insert($fname, $lname)
{
$insert = "INSERT INTO table (firstname, lastname)
VALUES ('$fname','$lname')";
mysql_query($insert)
or die("could not insert:".mysql_error());
header('Location: blah.php');
}
function emptyCheck($fname, $lname)
{
if ($fname == "" || $lname == "")
{
echo "Please fill in all the fields.";
}
}
}
?>
このページには次のように表示されます。
<?php
include('database.php');
$db = new Database();
$sql = "SELECT *
FROM tables";
if ($_GET['sort'] == 'id')
{
$sql .= " ORDER BY id";
}
elseif ($_GET['sort'] == 'fn')
{
$sql .= " ORDER BY firstname";
}
elseif ($_GET['sort'] == 'ln')
{
$sql .= " ORDER BY lastname";
}
?>
<html>
<body>
<table>
<tr>
<td>
<table border="1" align="center">
<tr>
<th><a href="blah.php?sort=id">ID</a></th>
<th><a href="blah.php?sort=fn">First Name</a></th>
<th><a href="blah.php?sort=ln">Last Name</a></th>
<th>Edit</th>
<th>Delete</th>
</tr>
<?php
$db->query($sql);
?>
</table>
</table>
<a Href="new.php">Add new Record</a>
</body>
</html>
これが本当に明白な場合は申し訳ありませんが、私はwebdevでひどく、mysqliを初めて使用します。ありがとう。