PHP数组中的可疑语法问题可与数据对象一起使用



使用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);

解析错误:语法错误,意外'('('('),在第82行82

上,在/htmladdress.php中期望t_string或t_variable或'{'{'''或'$'

第82行是特别是从变量$ dbh到$ sth

开始的。

我还执行了此代码,并用引号包裹的数据数组中的所有变量,结果相同。

什么

解析错误:语法错误,意外 t_variable或'{''或'$'in/htmladdress.php在第82行

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

应该是

# 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代码中的错误。

最新更新