note 52506 deleted from function.mysql-real-escape-string by nlopess

From: Date: Sat, 07 May 2005 18:33:33 +0000
Subject: note 52506 deleted from function.mysql-real-escape-string by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-89087@lists.php.net to get a copy of this message
Note Submitter: ---- mysql_real_escape_string() does not work for BINARY values!!! I'm using PHP 4.3.10 and found my web application was storing incorrect values in the database after using mysql_real_escape_string(pack()). Anyone trying to put raw data into a SQL statement should use hex values. Once you have a hex string, use my convenient function for making mySQL happy: function db_hex_to_bin($hexval) { return("CAST(0x$hexval AS BINARY)"); } Example: $binvalue = 'f9c3'; $sqlvalue = db_hex_to_bin($binvalue); $query = "SELECT * FROM mytable WHERE binfield = $sqlvalue"; Both mySQL and PHP have extremely poor documentation for binary functionality, and there may be some secret tricks I don't know about. On the other hand, hex values make debugging MUCH easier. Enjoy, -- Miqro

« previous php.notes (#89087) next »