开发者

MySQL Queries using Doctrine & CodeIgniter

EDIT: The reason why my Doctrine queries (see below) did not work/produced those errors was because I left out

ci_doctrine.

when creating this database:

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`
)
)

END OF EDIT

How do I write plane SQL queries using开发者_StackOverflow社区 Doctrine connection object and display the results? For example, how do I perform:

SELECT * FROM table_name WHERE column_name LIKE '%anything_similar_to_this%';

using Doctrine something like this (this example does not work)

 $search_key = 'search_for_this';

 $conn = Doctrine_Manager::connection();

 $conn->execute('SELECT * FROM table_name WHERE column_name LIKE ?)',  $search_key);

 echo $conn;  

I've also tried:

$search_key = 2;
$q = new Doctrine_RawSql();
$result = $q->select('column_name')
  ->from('table_name')
  ->where('id = ?', $search_key)
  ->execute();

echo $result;


Doctrine uses It's own query language called DQL. And it uses a query class to handle the queries called Doctrine_Query. Through this class you can build a query using the so called query builder.

You can look at the documentation at http://doctrine-project.com to find out how it works exactly.


You have an unnecessary parenthesis which is probably causing an error. Try changing:

SELECT * FROM table_name WHERE column_name LIKE ?)

to:

SELECT * FROM table_name WHERE column_name LIKE ?

If it still doesn't work, try posting the error message.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜