Bill,

I think Aycko was speaking about a different problem than you described.

Aycko> The fieldname is ':field:name' without table prefix.

In fact what Aycko described is possible, but not with Zend_Db, for the reasons 
I gave earlier. I also believe the framework should not impose conventions on 
DB schemas used by ZF developers.


For example, the SQL below does work with MySQL

CREATE TABLE `test` (
 `id` tinyint(4) NOT NULL auto_increment,
 `:stuff:more` smallint(6) NOT NULL,
 PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

INSERT INTO `test` (`id`, `:stuff:more`) VALUES (1, 0);

SELECT `:stuff:more`  FROM `test`;


Gavin> This general problem is recognized, and a solution has been proposed:
Gavin> http://framework.zend.com/wiki/x/RB8
Gavin> See the section titled "Mapping Identifiers between DB and PHP".

Cheers,
Gavin

Bill Karwin wrote:
Aycko Maerzke wrote:
I tried an query like this:

$db->query("SELECT `:tablename:filedname` FROM `table`");

You shouldn't use parameters for table and column names. Parameters are used in SQL only to supply values, not identifiers or any other part of syntax. Also, the identifier delimiter syntax you used above won't work even if you execute it in the MySQL command-line client. You need to do the delimiters on _each_ of the table name and the column name.

For example, the following doesn't work because it looks for a column called foo.bar in the table foo.

 SELECT `foo.bar` FROM `foo`

You need to delimit each identifier separately to make it clear that they are two separate identifiers:

 SELECT `foo`.`bar` FROM `foo`

If you need to make the table referenced in the select-list depend on the table queried in the FROM clause, you should use a correlation name:

 SELECT f.`bar` FROM `foo` AS f

Regards,
Bill Karwin


Reply via email to