向准备好的语句添加错误消息

时间:2013-07-07 20:44:00

标签: php pdo

我正在尝试将mysql_query转换为准备好的语句,但是它默默地失败了,我不确定我哪里出错了。这是表格的proc.php页面:

$db = new PDO('mysql:host=XXX;dbname=XXX;charset=utf8', 'XXX', 'XXX');

if ($_POST['submit']) {
    $type = $_POST['type'];
    $auth1_lname = trim($_POST['auth1_lname']);
    $auth1_fname = trim($_POST['auth1_fname']);
    $today =  date("Y-m-d"); 

$stmt = $db->prepare("INSERT INTO table_base ( type , publ_date , auth1_lname , auth1_fname ) 
        VALUES (:type, :today, :auth1_lname , :auth1_fname) ");
    $stmt->bindParam(':type', $type);
    $stmt->bindParam(':today', $today);
    $stmt->bindParam(':auth1_lname', $auth1_lname);
    $stmt->bindParam(':auth1_fname', $auth1_fname);
    $stmt->execute();

    $bid = $db->lastInsertId();

    $subj_area = $_POST['subj_area'];
    $subject = 'subj_area';
    $subjs = '';

$stmt = $db->prepare("INSERT INTO table_meta (bid, key, value) VALUES (:bid, :key, :value)");
    $stmt->bindParam(':bid', $bid);
    $stmt->bindParam(':key', $subject);
    $stmt->bindParam(':value', $subjs, PDO::PARAM_STR);
    foreach($subj_area as $subjs) {
       $stmt->execute();
    }

    $geo_area = $_POST['geo_area'];
    $geograph = 'geo_area';
    $geos = '';

$stmt = $db->prepare("INSERT INTO table_meta (bid, key, value) VALUES (:bid, :key, :value)");
    $stmt->bindParam(':bid', $bid);
    $stmt->bindParam(':key', $geograph);
    $stmt->bindParam(':value', $geos, PDO::PARAM_STR);
    foreach($geo_area as $geos) {
       $stmt->execute();
    }
}   
  1. 我不确定我是否正确行事。
  2. 我在其他地方看到了关于你的PHP必须使用PDO这么高的评论,但PDO上的php.net页面没有列出PHP要求。我没有b / c我的PHP5主机没有合适的驱动程序?
  3. 有没有办法添加骰子(mysql_error()),所以至少它不会是一个无声的失败?

0 个答案:

没有答案