Need Programming Assignment Help?

Get Help with Programming Assignment in Java, C/C++, Dot Net, PHP, Database and UML Diagrams

Mysql Escape String in PHP

MySQL Escape String in PHP Program

A MySQL connection is required before using MySql escape string() otherwise an error of level E WARNING is generated, and FALSE is returned. If link identifier isn’t defined, the last MySQL connection is used.

<?php 
function mysql_escape_string($s) 
{ 
 $sl=strlen($s);

for ($a=0;$a<$sl;$a++) 
 { 
 $c=substr($s,$a,1);

switch(ord($c)) 
 { 
 case 0: 
 $c = "\\0"; 
 break; 
 case 10: 
 $c = "\\n"; 
 break; 
 case 9: 
 $c = "\\t"; 
 break; 
 case 13: 
 $c = "\\r"; 
 break; 
 case 8: 
 $c = "\\b"; 
 break; 
 case 39: 
 $c = "\\'"; 
 break; 
 case 34: 
 $c = """; 
 break; 
 case 92: 
 $c = "\\\\"; 
 break; 
 case 37: 
 $c = "\\%"; 
 break; 
 case 95: 
 $c = "\\_"; 
 break; 
 } 
 $s2.=$c; 
 } 
 return $s2; 
} 
?>