この方法で Zend Framework 2 Db Adapter を使用してクエリを実行しようとしています。
$db = new Adapter(array(
'driver' => 'oci8',
'username' => 'myusername',
'password' => 'mypassword',
'connection_string' => 'myconnectionstring',
'charset' => 'utf8',
));
$sql = 'SELECT lastname FROM accounts WHERE username = ?';
$statement = $db->createStatement($sql, array('luca'));
$result = $statement->execute();
しかし、PHP には次のメッセージが表示されます。
[23-May-2013 10:23:30 Europe/Rome] PHP Fatal error: Uncaught
exception 'Zend\Db\Adapter\Exception\RuntimeException'
with message 'ORA-00911: invalid character' in
/var/www/zend/server/library/ZF2-.2.0/library/Zend/Db/Adapter/Driver/Oci8/Statement.php:261
Stack trace:
#0 /var/www/html/secure/zendAuth2.php(92):
Zend\Db\Adapter\Driver\Oci8\Statement->execute()
#1 {main}
thrown in /var/www/zend/server/library/ZF2-2.2.0/library/Zend/Db/Adapter/Driver/Oci8/Statement.php on line 261
SQL の無効な文字は「?」のようです。私は何を間違っていますか?フレームワークのマニュアルを読むと正しいようです ( http://framework.zend.com/manual/2.2/en/modules/zend.db.adapter.html#query-prepation-through-zend-db-adapter-adapter- query ) しかし、それでもこのエラーが発生します。代わりに私が使用する場合
$sql = 'SELECT lastname FROM accounts WHERE username = :username';
$statement = $db->createStatement($sql, array(':username' => 'luca'));
$result = $statement->execute();
それは正常に動作します。
助けてくれてありがとう。