I've been migrating a website from one server to another. The code is massive, so naturally I've had my share of problems. I believe they're all solved except for this persistent one:
On a particular page, I get the following error:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: fetch mode requires the colno开发者_如何转开发 argument' in /home/username/public_html/admin/lib/database.inc.php:59
The line referenced:
$myResult->setFetchMode(PDO::FETCH_COLUMN);
I've been back and forth through the PDO documentation, so my diagnosis was originally that setting the fetch mode to PDO::FETCH_COLUMN required also setting a column number - no great deduction there. So I tried a value of 0 as the second argument. The page spent more than 30 seconds loading and got a PHP timeout. Same for a value of 1, and then I decided this wasn't the path to success.
Now, the really perplexing thing is that this site works perfectly on my local test machine without any modification, as well as on the original production server. I don't have easy access to the specs on the old server, but I know that those of my local test machine match those of the new server pretty damn closely.
Specifically:
Local PHP: 5.3.3
Remote PHP: 5.3.4
Local MySQL: 5.1.37
Remote MySQL: 5.0.91
Since I know the code is good with some configuration, I'm hoping someone knows the magic switch I can flip.
--EDIT--
Even with error_reporting set to E_ALL | E_STRICT on the local machine, this PDO exception doesn't appear.
Solved. Don't ask me why, but downgrading PHP to a particular version - as recommended by the original devs - did the trick. Nevermind that it was working fine locally with a more recent version. It just worked.
Old question I know, but I was getting the same error and thought I'd post what I found. I solved it by using prepared statements and passing PDO::FETCH_COLUMN
to fetchAll()
.
$query = $database->prepare($sql);
$query->execute();
$result = $query->fetchAll(PDO::FETCH_COLUMN);
I don't know why it works that and not with $database->query()
. I don't need prepared statements here because I am not passing any parameters to the SQL, but it works so I roll with it. Hopefully that helps someone else who has this same error.
精彩评论