Re: quotes in SQL command

From: Date: Mon, 08 Dec 2003 06:45:18 +0000
Subject: Re: quotes in SQL command
References: 1 2  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-9351@lists.php.net to get a copy of this message
Nguyen Hung Vu St wrote:
Stefan Neufeind wrote:
On 8 Dec 2003 at 13:19, Nguyen Hung Vu ST wrote:
Hello all, I tried to do an SELECT in PEAR:DB like below $sth = $db_pear->prepare("SELECT * FROM lists WHERE ID = ?"); but the problem is, that is OK for MySQL but in PostgreSQL, we will have to put ID inside double quotation ("), and it becomes $sth = $db_pear->prepare("SELECT * FROM lists WHERE \"ID\" = ?"); That is my problem when I tried to make my program works on both MysQL and PostgreSQL. Any ideas?
Why not use single-quotes around the string?
        'SELECT * FROM lists WHERE "ID" = ?'
Regards, Stefan
Hello Stefan, I think you did not get me fully. Here is another code using prepare and execute $sth = $db_pear->prepare("SELECT Email FROM users WHERE Email = ? AND ListID = ?"); $check_values = array($email[$i], $listID); $check = $db_pear->execute($sth, $check_values); if(DB::isError($check)) {
    echo "<br>".$check->getDebugInfo()."<br>";
} This did not work get getDebugInfo() returen error: --- error msg ------- SELECT Email FROM users WHERE Email = 'df@ya.com' AND ListID = '1' [nativecode=ERROR: Attribute 'email' not found ] --- end error msg ---- Yeah, "native code=ERROR". I noticed that SELECT Email FROM users WHERE Email = 'df@ya.com' AND ListID = '1' has a wrong syntax in Pgsql. Right statement should be SELECT Email FROM users WHERE "Email" = 'df@ya.com' AND "ListID" = '1' -> quote issue ^.^ Cheers Hung Vu
Well, then start using the quotes correctly. OR you could use a variable set to the correct "Field quote" for the DB you're using. OR you could use an SQL creation package which shoudl do all of that for you (Such as DB_DataObject). -- paperCrane <Justin Patrin>

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