CREATE TABLE `ci_doctrine`.`user` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`username` VARCHAR(255) NOT NULL ,
`password` VARCHAR(255) NOT NULL ,
`first_name` VARCHAR(255) NOT NULL ,
`last_name` VARCHAR(255) NOT NULL ,
UNIQUE (`username`
)
)
:爲什麼我的學說查詢(見下文)沒有工作/產生這些錯誤是因爲我創建這個數據庫時離開了
ci_doctrine.
原因
END OF EDIT
如何使用Doctrine連接對象編寫平面SQL查詢並顯示結果?例如,如何執行:使用原則是這樣的(這個例子不工作)
$search_key = 'search_for_this';
$conn = Doctrine_Manager::connection();
$conn->execute('SELECT * FROM table_name WHERE column_name LIKE ?)', $search_key);
echo $conn;
我也試過
SELECT * FROM table_name WHERE column_name LIKE '%anything_similar_to_this%';
:
$search_key = 2;
$q = new Doctrine_RawSql();
$result = $q->select('column_name')
->from('table_name')
->where('id = ?', $search_key)
->execute();
echo $result;
+1。我改變了:$ conn-> execute('SELECT * FROM table_name WHERE column_name LIKE?)',$ search_key);到$ conn-> execute('SELECT * FROM table_name WHERE column_name LIKE?',$ search_key);並得到以下錯誤:嚴重性:4096消息:傳遞給Doctrine_Connection :: execute()的參數2必須是一個數組,字符串給定,調用...嚴重性:警告消息:爲foreach()提供的無效參數致命錯誤:帶有消息'SQLSTATE [HY093]的未捕獲異常'Doctrine_Connection_Mysql_Exception':無效參數編號:未綁定任何參數... – Anthony 2010-04-24 13:55:39