夺命雷公狗---PDO NO:9 使用PDO准备语句并执行语句4

<?php
header(“Content-Type:text/html;charset=utf-8″);
try{
    $pdo = new PDO(“mysql:host=localhost;dbname=xsphp”,’root’,”);
    $pdo -> setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
    $pdo -> query(‘set names utf8′);
}catch(PDOException $e){
    echo “数据库连接失败:”.$e -> getMessage();
    exit;
}
try{
    $stmt = $pdo -> prepare(“insert into stu(name,age) values(:name,:age)”);
    $stmt -> execute(array(‘name’=>’fengzi’,’age’=>’55’));
    $stmt -> execute(array(‘name’=>’xiaoge’,’age’=>’54’));
    $stmt -> execute(array(‘name’=>’tianren’,’age’=>’11’));
    $stmt -> execute(array(‘name’=>’xiaoxin’,’age’=>’10’));
}catch(PDOException $e){
    echo “错误:”.$e -> getMessage();
}
原文地址:https://www.cnblogs.com/leigood/p/5032799.html