php xml写入数据库中,PHP读取xml并写入数据库示例
$xml = simplexml_load_file(‘books.xml‘);
// print_r($xml);
// echo "
";
$t = $xml->to;
$f = $xml->from;
$h = $xml->heading;
$b = $xml->body;
$dsn = "mysql:host=localhost;dbname=demo";
$username = "root";
$password = "00000000";
$conn = new PDO($dsn,$username,$password);
try{
$conn->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("insert into xml(t,f,heading,body) values(:t,:f,:h,:b)");
$stmt->bindParam(‘:t‘,$t);
$stmt->bindParam(‘:f‘,$f);
$stmt->bindParam(‘:h‘,$h);
$stmt->bindParam(‘:b‘,$b);
$stmt->execute();
echo "success";
}catch(PDOException $e){
echo "Error" . $e->getMessage();
}
$conn = null;
xml文件:
Tove
Jani
Reminder
原文:https://www.cnblogs.com/connectionworld/p/11076617.html
總結
以上是生活随笔為你收集整理的php xml写入数据库中,PHP读取xml并写入数据库示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 学php为什么要学linux,为什么 P
- 下一篇: php接口调用实例源代码,小蚂蚁学习AP