メソッドを使用して、複数の XML ファイルから複数のノード値を MySQL に挿入したいと考えていますxpath
。コードは次のとおりです。
<?php
$path="fs/";
$con = mysql_connect("localhost","sufi","1234");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
if ( $handle = opendir($path) ) {
$files = array();
while ( ($file = readdir($handle)) !== false ) {
$files[] = $file;
}
sort($files);
foreach ( $files as $file ) {
$xml = simplexml_load_file("$file");
$products[0] = (string)current($xml->xpath("/sioct:BoardPost/sioc:content"));
$products[1] = (string)current($xml->xpath("/sioct:BoardPost/dcterms:created"));
$products[2] = (string)current($xml->xpath("/sioct:BoardPost/@rdfabout"));
extract($products);
mysql_query("INSERT INTO forum (txt_content,txt_date,txt_about)
VALUES ( '".mysql_escape_string($products[0])."',
'".mysql_escape_string($products[1])."',
'".mysql_escape_string($products[2])."')" );
}
}
?>
しかし、これにより次のエラーが発生します。
警告: simplexml_load_file(.) [function.simplexml-load-file]: ストリームを開くことができませんでした: 22 行目の C:\wamp\www\readfiles.php で許可が拒否されました。警告: simplexml_load_file() [function.simplexml-load-ファイル]: I/O 警告: 外部エンティティ "." の読み込みに失敗しました C:\wamp\www\readfiles.php の 22 行目、致命的なエラー: 23 行目の C:\wamp\www\readfiles.php の非オブジェクトに対するメンバー関数 xpath() の呼び出し。
これを処理する方法をいくつか提案してください。