|
|
|
I ran one of my database front-ends that worked great in PHP3, under PHP4 and found that
back-slashes started poping up like rabbits on fertility hormones. After a little research into
the problem, I found out what it was: mysql_escape_string, a function not availble in PHP3
was implemented "transparently" in PHP4 and (unfortunately) was installed "backwards": It
escapes the result set, which is not how string escaping was intended. The fix: I've made a fix
called mysql_unescape_string. You won't find an analog of it at www.mysql.com because its a
bastard function specifically for taking care of the PHP4 implementation problem. See the
example section for usage of it... (Also, see the "mysql_escape_string" function in this same
section for my original fix for string escaping in MySQL)
<?php
function mysql_unescape_string($s)
{
$sl=strlen($s);
for ($a=0;$a<$sl;$a++)
{
$c=substr($s,$a,1);
if ($c=="\\")
{
switch(substr($s,$a+1,1))
{
case "0":
$c="\0";
break;
case "n":
$c="\n";
break;
case "t":
$c="\t";
break;
case "r":
$c="\r";
break;
case "b":
$c="\b";
break;
case "\'":
$c="'";
break;
case "\"":
$c="\"";
break;
case "\\":
$c="\\";
break;
case "%":
$c="\%";
break;
case "_":
$c="_";
break;
default:
echo("unhandled exception!");
}
// advance the counter because we are pealing off the char after the scanned \
$a++;
}
$s2.=$c;
}
return $s2;
}
?>
Example :
========
In PHP3, the code:
...
$row=mysql_fetch_row($res);
$fielddata=strval($row[0]);
....
becomes (in PHP4):
....
$row=mysql_fetch_row($res);
$fielddata=mysql_unescape_string(strval($row[0]));
|
|
| This program allows you to upload an ODBC ressource - i.e. an MS-Access database to a MySQL server. Categories : Databases, MySQL, Complete Programs, PHP, Databases | | | bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager Categories : MySQL, PHP, MySQL, Complete Programs, Databases | | | Accepts a database & hostname from a user and then HTTP username and password. Uses this to connect to a MySQL database. Produces a form based on the tables it finds there to allow the user to do SELECTs, INSERTs, and DELETEs. Categories : Databases, PHP, MySQL, Complete Programs | | | phpAds, a complete banner and ad management system with detailled tracking and stats. Categories : MySQL, Complete Programs, Ecommerce, PHP, Databases | | | Point and Click Interface ala MS Access for creating SQL statements. Categories : MySQL, Complete Programs, General SQL, PHP, Databases | | | Message of the Day - Random Message (Needs MySQL!) Categories : Databases, HTML and PHP, PHP, MySQL | | | email new items in db Categories : PHP, Email, Databases, MySQL, Beginner Guides | | | Alternating background color for HTML table rows Categories : PHP, Databases, MySQL, HTML and PHP | | | color codes for positive and negative numbers Categories : PHP, MySQL, Databases, HTML | | | Authorize Me! An authentication script. Categories : MySQL, Databases, Authentication, PHP | | | A very simple way to build and do a hierarchical html categories browser without javascript , just using html php and mySql
Categories : HTML and PHP, Databases, Algorithms, PHP, MySQL | | | Linked comboboxes with php-mysql & javascript Categories : PHP, Java Script, Databases, MySQL | | | mysql_escape_string Categories : PHP, MySQL, Databases, Strings | | | Automatically printing the contents of an sql table in MySQL. Categories : MySQL, PHP, HTML and PHP, Databases | | | usercounter class Categories : PHP, PHP Classes, Databases, MySQL, Environment Variables | |
|
|
|