Jump to content

Objects & mysql_real_escape_string


2levelsabove

Recommended Posts

Try:

 

foreach ($this as $value) { $value = mysql_real_escape_string($value); }

 

Keep in mind, this will apply mysql_real_escape_string to every data member of your object.  This also assumes you're using this code from within the object itself, like so:

 

class test
{
   private $firstName = "Forrest";
   private $lastName = "Gump";

   public function escapeData()
   {
      foreach ($this as $value) { $value = mysql_real_escape_string($value); }
   }
}

$example = new test();
$example->escapeData();

I know this will sound retarded but I did it because i like the object syntax :(

 

As opposed to writing :

 

$sql="INSERT INTO DB VALUES(".$_POST['test'].")";

 

I can do

 

$sql="INSERT INTO DB VALUES("$obj->test")";

 

 

I know this is sad.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.