PDO SUCKS! For Prepared Statements...

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
Hendeca
Forum Commoner
Posts: 29
Joined: Tue Nov 18, 2008 1:27 pm

PDO SUCKS! For Prepared Statements...

Post 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!
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: PDO SUCKS! For Prepared Statements...

Post by josh »

Check out the API docs for Zend_Select ( Zend framework component )
Post Reply