2008年12月19日星期五

[fw-db] Re: [Postgresql] Syntax error

Ok sorry for the waist of time, I found the answer in the zend
framework manual, here :
http://framework.zend.com/manual/en/zend.db.html#zend.db.adapter.connecting.parameters.example2

So, I modified the index.php (see below) but I still have the same
query syntax error... Am I stupid or I just didn't sleep enough this
night?!?!

/**
* Database configuration
*/
Zend_Loader::loadClass('Zend_Db');
Zend_Loader::loadClass('Zend_Db_Table');
$params = array('host' => DB_SERVER,
'username' => DB_USER,
'password' => DB_PASSWORD,
'dbname' => DB_NAME,
'options' => array(Zend_Db::AUTO_QUOTE_IDENTIFIERS => true));
$db = Zend_Db::factory(DB_TYPE, $params);
$db->setFetchMode(Zend_Db::FETCH_OBJ);
Zend_Db_Table::setDefaultAdapter($db);
$registry->set('db', $db);


On Fri, Dec 19, 2008 at 11:08 AM, Thomas VEQUAUD
<thomas.vequaud@gmail.com> wrote:
> Hi there!
>
> I was running a MySQL database but from now I need more stuff... So I
> decided to install a PostgreSQL database on my development
> environment. I added a [pgsql] section in my config.ini file...
> Anyway, when I try to launch the index of my website, I get a SQL
> syntax error with the following query :
> SELECT *
> FROM "user" AS "us"
> INNER JOIN "is" ON us.user_id = is.user_id
> INNER JOIN "role" AS "ro" ON is.role_id = ro.role_id
> WHERE (ro.role_type <> 2 AND ro.role_type <> 1)
> ORDER BY "user_date" DESC
>
> This query is generated by my model class 'User' with the following method:
> public function getLastRegistered()
> {
> $select = $this->select();
> $select->setIntegrityCheck(false)
> ->from(array('us' => 'user'))
> ->join('is', 'us.user_id = is.user_id')
> ->join(array('ro' => 'role'), 'is.role_id = ro.role_id')
> ->where('ro.role_type <> '.ROLE_TYPE_INACTIVE.' AND ro.role_type
> <> '.ROLE_TYPE_BANNED)
> ->order('user_date DESC')
> ->limit(0, 10);
> return ($this->fetchAll($select)->toArray());
> }
>
> I have to add double-quotes (") around every alias and field names by
> myself? I hope no and maybe Zend_Db has a "magic" function to do that
> work? Cause, as you know, following the database engine, you have to
> insert double-quotes (") or back-quote (`)...
>
> Thank you for your help!
>
> --
> Thomas VEQUAUD http://thomas.vequaud.free.fr/
> Ingénieur Systèmes pour le compte d' ITS GROUP
> Bénévole et secouriste à la Croix-Rouge Française
>

--
Thomas VEQUAUD http://thomas.vequaud.free.fr/
Ingénieur Systèmes pour le compte d' ITS GROUP
Bénévole et secouriste à la Croix-Rouge Française

没有评论: