Pear MDB2 autoPrepare question

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
georgeoc
Forum Contributor
Posts: 166
Joined: Wed Aug 09, 2006 4:21 pm
Location: London, UK

Pear MDB2 autoPrepare question

Post by georgeoc »

Hi all.

I've been using the PEAR MDB2 package as database abstraction for my application. I am pretty happy with it, and chose it particularly because of the automatic table creation and manipulation from XML schema.

For all queries I've needed so far in my app, I've used autoPrepare() or autoExecute(). I get the field names and types from the XML files mentioned above - they are parsed on installation of the app and a hash of the field names, sizes, types etc. is stored for future use. So, for example, I can make a call to my db interface like this:

Code: Select all

$db->insert('posts', array($post_id, $uid, $subject, $message));
... and the db class will look up the field names and types of the 'posts' table, run autoPrepare() to build the statement and execute it. It's working brilliantly.


My issue is that I now need to build more complex SQL statements. The first one I've come across is something like the following:

Code: Select all

UPDATE forums SET forum_posts = forum_posts + 1
Now, is there any way I can autoPrepare() such a statement using MDB2? I've been trying to get my head round the docs, but the best I can find is this:
The values passed in $data must be literals. Do not submit SQL functions (for example CURDATE()). SQL functions that should be performed at execution time need to be put in the prepared statement. Similarly, identifiers (i.e. table names and column names) can not be used because the names get validated during the prepare phase.
Sure, I can do this using prepare(), but is there any way to do it with autoPrepare()?

Thanks for any help.
georgeoc
Forum Contributor
Posts: 166
Joined: Wed Aug 09, 2006 4:21 pm
Location: London, UK

Post by georgeoc »

On second thoughts, perhaps this post would be more appropriate in the PHP - Code forum? Sorry about that.
Post Reply