Page 1 of 1

PDO SUCKS! For Prepared Statements...

Posted: Thu Feb 12, 2009 8:30 pm
by Hendeca
Or at least that's the impression I've gotten both from using it and reading about other peoples' problems. However I wanna run my problem past you guys to see if there's something I'm missing. Here's just a random example:

Code: Select all

 
<?php
$tablename = 'photos';
$currentImage = $_GET['image'];
$dsn = 'mysql:dbname=testdb';
$user = 'user';
$pwd = 'pwd';
$conn = new PDO($dsn, $user, $pwd);
$st = $conn->prepare("SELECT * FROM ? WHERE file_name='$currentImage'");
$st->bindParam(1, $tablename);
$st->execute();
$result = $st->fetch(PDO::FETCH_ASSOC);
 
The above script is not from the site, it is an example, but I have tried many variations of this, and I seem to always either get an empty $st variable or $st as a PDOStatement object that doesn't fetch anything. I know that the mysql info is correct because this same script works with a query() method. The problem is I want to pass a variable to the query so that I can name the page the same name as the table and draw the tablename from the $_SERVER['SCRIPT_NAME'] variable. Is this a problem everyone has? I've heard that PDO has a lot of bugs in terms of prepared statements. I've also tried using the method where you prepare a statment and then just use execute(array($var)) with no success. I've been planning on just using mysqli instead. Anyone know what's up? I'm using dreamhost, maybe it has to do with the version of mysql on the server?

Thanks for your help!

Re: PDO SUCKS! For Prepared Statements...

Posted: Thu Feb 12, 2009 10:13 pm
by josh
Check out the API docs for Zend_Select ( Zend framework component )