このエラーが発生しましたが、理由がわかりません:
致命的なエラー: オブジェクト以外でのメンバー関数 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();
}