php数组中可疑的语法问题,用于数据对象

时间:2012-11-02 20:14:51

标签: php arrays pdo

使用指南suggested by netnuts来使用数据对象进行数据库访问,特别是与未命名的占位符相关

# the data we want to insert
$data = array('Cathy', '9 Dark and Twisty Road', 'Cardiff');
$STH = $DBH->("INSERT INTO folks (name, addr, city) values (?, ?, ?);
$STH->execute($data);

遗憾的是,代码

似乎产生了解析错误
# the data we want to insert
$data = array($first_name, $second_name, $email_from, $telephone, $dateofbirth, $addresslone, $addressltwo, $townnm, $countynm, $typeapp, $issubscribed);
$STH = $DBH->("INSERT INTO members (fname, sname, email, phone, dob, addressl1, addressl2, town, county, type, subscribed) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$STH->execute($data);
  

解析错误:语法错误,意外'(',期待T_STRING或T_VARIABLE或' {'或' $'在/HTMLADDRESS.php上第82行

第82行具体是从变量$ DBH赋值给$ STH

开始的

我还使用引号括起的数据数组中的所有变量执行此代码,结果相同。

1 个答案:

答案 0 :(得分:2)

什么

  

解析错误:语法错误,意外'(',期待T_STRING或   T_VARIABLE或' {'或者' $'在第82行的/HTMLADDRESS.php中

告诉你,在->之后它没有期待(,这是正确的,因为应该有一个方法调用。

应该是

# the data we want to insert
$data = array($first_name, $second_name, $email_from, $telephone, $dateofbirth, $addresslone, $addressltwo, $townnm, $countynm, $typeapp, $issubscribed);
$STH = $DBH->prepare("INSERT INTO members (fname, sname, email, phone, dob, addressl1, addressl2, town, county, type, subscribed) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$STH->execute($data);

它在netnuts代码中出错。