|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2005-11-21 20:03 UTC] jay at cheakamus dot com
 Description: ------------ While trying to implement PDO with MySQL on a new project (first attempt at using PDO) I got stumped with preparing a query statement. I have combed through the examples at http://wiki.cc/php/PDO_Basics and implemented the following code. It returns nothing. I can prepare the statement with no bound variables and it works fine. For reference: PHP 5.0.5-2ubuntu1 (breezy) MySQL 4.1.12-1ubuntu3 (breezy) PDO-1.0RC2 (pear install) PDO_MYSQL-1.0RC2 (pear install) Aside from adding the extensions for pdo and pdo_mysql to php.ini this is a stock Breezy PHP and mysql installation. Reproduce code: --------------- <?php print "<pre>\n"; $db = new PDO("mysql:dbname=pdotest;host=localhost", "", ""); $db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); $stmt = $db->prepare( "SELECT * FROM feeds WHERE url = :url" ); $url = "http://www.planet-php.net"; $stmt->bindParam( ":url", $url ); $stmt->execute(); while( $row = $stmt->fetch() ) { print_r( $row ); } print "</pre>\n"; ?> Expected result: ---------------- <pre> Array ( [id] => 1 [0] => 1 [name] => Planet-PHP [1] => Planet-PHP [url] => http://www.planet-php.net [2] => http://www.planet-php.net [feed] => http://www.planet-php.net/rdf/ [3] => http://www.planet-php.net/rdf/ ) </pre> Actual result: -------------- <pre> </pre> PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 10:00:02 2025 UTC | 
Can you try changing your bindParam call to this: $stmt->bindParam("url", $url); Also, add a: $stmt->debugDumpParams(); call after you prepare the query. (the : prefix should work, just wondering if it is badly implemented).