DB:: query versus prepare

From: Date: Fri, 16 Jan 2004 18:30:25 +0000
Subject: DB:: query versus prepare
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-10191@lists.php.net to get a copy of this message
I've RTFM on the DB:: class, but I'm running into a problem using it. I'm attempting to do an update in an SQL table. If I use "prepare", everything works fine. If I use "query", it does not appear to bind the variables into the statement. WORKS: $sql = "update testdb_user_levels set " . "level_number = ?, level_desc = ? where level_id = ?"; $sth = $dbh->prepare( $sql ); $result = $dbh->execute( $sth, array( $level_number, $level_desc, $level_id ) ); if (DB::isError($result)) . . FAILS: $sql = "update testdb_user_levels set " . "level_number = ?, level_desc = ? where level_id = ?"; $result = $dbh->query( $sql, array( $level_number, $level_desc, $level_id ) ); if (DB::isError($result)) . . The example above fails, and the resulting error message says that I have a syntax error. The return from Mysql shows that the syntax error occurs at the first "?", indicating (I believe) that the DB class never replaced the "?" with the values I passed in. Here's my error code: userinfo = (string) update testdb_user_levels set level_number = ?, level_desc = ? where level_id = ? [nativecode=You have an error in your SQL syntax near '?, level_desc = ? where level_id = ?' at line 1] I have to imagine I'm completely missing something, but I don't see it- the documentation shows I should be able to pass an array of values in to query and have it do the substitutions. Anyone care to hit me with a cluehammer? Thanks, --Ross

« previous php.pear.general (#10191) next »