Re: Quote String

From: Date: Tue, 03 Jul 2001 13:19:25 +0000
Subject: Re: Quote String
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-540@lists.php.net to get a copy of this message
At 11:19 AM +0200 7/3/01, Tomas V.V.Cox wrote:
Sorry for not to follow the thread but I recently have suscribed to the list. Please test this patch to the pear/DB/mysql.php, so if works I'll commit the change to the quote string behavoir. The same for the sybase extension. For the question about null values I don't see any way for inserting them, but the needed change in executeEmulateQuery() for supporting it is trivial. What do you think to add the unquoted NULL string when the null (constant) value is given?
Personally, I think that's the corrrect behavior. But on the other hand, it wouldn't be so difficult to make quoteString() do that to, such that: quoteString("a") => "'a'" quoteString (null) => "NULL" The intent of quoteString is to return a value that can be added to a query string. This would allow you to do so more generally without having to write stuff like: $query = "INSERT INTO tbl_name SET col_name = " . ($x == null ? "NULL" : $conn->quoteString ($x)); Instead, you'd just write: $query = "INSERT INTO tbl_name SET col_name = ". $conn->quoteString ($x); That's how the quote() method in DBI works. (Am I allowed to say that here? :-)
For example: $data = array(2, null, 'two'); $sth = $db->prepare("INSERT INTO numbers VALUES (?,?,?)"); $db->execute($sth, $data); => INSERT INTO numbers VALUES (2, NULL, 'two') Tomas V.V.Cox Attachment converted: stone:quote_mysql.diff (TEXT/R*ch) (0001F13F) Attachment converted: stone:quote_sybase.diff (TEXT/R*ch) (0001F140)
-- Paul DuBois, paul@snake.net

« previous php.pear.dev (#540) next »