我收到此错误并且不知道原因:
致命错误:在非对象上调用成员函数 bind_param()
$string = file_get_contents($url, false, $context);
$xml = new SimpleXMLElement($string);
if ($stmt->prepare("INSERT INTO table (id, filePointer, amount, description)
VALUES (?, ?, ?, ?)"))
{
foreach ($xml->machine as $machine)
{
$stmt->bind_param('ssss', $machine->id, $machine->images->image->filePointer, $machine->advertised_price->amount, $machine->description);
// Execute the query
$stmt->execute();
$stmt->close();
}
}
这是我如何调用表格:
//Create table
$create_table =
'CREATE TABLE IF NOT EXISTS table
(
id INT NOT NULL,
filePointer TEXT NOT NULL,
amount INT NOT NULL,
description TEXT NOT NULL
PRIMARY KEY(id)
)';
$create_tbl = $db->query($create_table);
if ($create_table)
{
echo "Table has been created";
}
else
{
echo "error!!";
}
以前我在 MyPHPAdmin 中制作表格。当我运行它然后检查我的数据库时,它没有创建表或更新它。我已经检查以确保它正在连接到数据库,并且据我所知它正在工作。
我的新 INSERT INTO 代码:
$stmt = $db->stmt_init();
if ($stmt->prepare("INSERT INTO table (id, filePointer, amount, description)
VALUES (?, ?, ?, ?)"))
{
$id = 0;
$filePointer = '';
$amount = 0;
$description = '';
$stmt->bind_param('isis', $id, $filePointer, $amount, $description);
foreach ($xml->machine as $machine)
{
$id = $machine->id;
$filePointer = $machine->images->image->filePointer;
$amount = $machine->advertised_price->amount;
$description = $machine->description;
if (!$stmt->execute())
{
echo "error : ".$id."<br />\n";
break;
}
}
$stmt->close();
}