j4mie / paris

A lightweight Active Record implementation for PHP5, built on top of Idiorm.
http://j4mie.github.com/idiormandparis/
996 stars 131 forks source link

raw_query parameters #69

Closed michaelward82 closed 11 years ago

michaelward82 commented 11 years ago

If this code works:

Model::factory('business')
    ->raw_query('DESCRIBE business')
    ->find_array();

Then should the following work?

Model::factory('business')
    ->raw_query('DESCRIBE :table', array('table' => 'business'))
    ->find_array();

At the moment I get an error:

Type: PDOException
Code: 42000
Message: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''business'' at line 1
File: /web/[PROJECT]/vendor/j4mie/idiorm/idiorm.php
Line: 349
treffynnon commented 11 years ago

No, database entities are escaped differently to values. You are trying to bind a value as a table name (entity) so it is being incorrectly escaped with apostrophes. The short of it; you cannot bind table names with PDO, which is what you're attempting to do with the code sample you have supplied.

michaelward82 commented 11 years ago

Thanks for clarifying!