我一直在构建一个 xml 解析器,应该从一个文件夹中删除所有 xml 文件,并且在解析主题后应该将数据保存在 mysql 表中。毕竟我收到以下错误。我不确定我做错了什么以及我应该如何调试它。
Warning: mysqli::prepare(): Couldn't fetch mysqli in E:\xampp\htdocs\XML_Parser\index.php on line 38
我的代码
class XMLFeeds{
public $obj;
protected $db_connect;
function __construct(){
// Read feeds and pass it to parser
$this->db_connect = @new mysqli('loalhost', 'root', '', 'test');
foreach(glob("feeds/*xml") as $filename) {
$obj = $this->parsing_feed(file_get_contents($filename, FILE_TEXT) );
$this->saveFeed($obj);
}
}
function parsing_feed($feed){
return simplexml_load_string($feed);
}
function saveFeed($obj){
foreach ($obj as $row){
$stmt = $this->db_connect->prepare("INSERT INTO tbl
( id,
prod_name,
category,
description,
image_url,
keywords,
sku,
target_url,
price,
warranty,
shipping_costs,
impressionurl,
lastupdated ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
if ($stmt === FALSE) {
die($mysqli->error);
}
$stmt -> bind_param("ssi",
$row->name,
$row->advertisercategory,
$row->description,
$row->imageurl,
$row->keywords,
$row->sku,
$row->buyurl,
$row->price,
$row->standardshippingcostm,
$row->impressionurl,
$row->lastupdated );
$stmt ->execute();
}
}
}
$parse = new XMLFeeds();