Jump to content

Recommended Posts

Hi,

 

I need some insight on how to go about fixing some broken code due to host upgrading PHP from 5.3 to 5.4 - see error below:

Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given in...

Yes, I aware, the two parameters that are required which would be as follow - with $db being the connection string:

mysqli_real_escape_string($db, $value);

Right now, the $db arguement is NOT in the 'mysqli_real_escape_string() function - read below to know why (that's what i need help to fix):

 

My problem is this function - itself - is being called within a function which (with PHP 5.3 used MYSQL extensions but PHP5.4 deprecated those functions and MYSQLi requiring 2 parameters as stated.... See that entire piece of code to see the issue which involves the 'quote_smart' function which executes the mysqli_real_escape_string() function inside 'quote_smart' function:

 

Here's the defined function, currently:

function quote_smart($value){

		   // Stripslashes if magic quotes is on

		   if(get_magic_quotes_gpc()) {

			   $value = stripslashes($value);

		   }

		   // Quote if not a number or a numeric string

		   if (!is_numeric($value)) {

			   $value = mysqli_real_escape_string($value);

		   }

		   return $value;

		}

and it's being called as such:

${$key} = quote_smart($value);

Thus, my problem - I'm not sure how to pass the mysqli link (arguement) into the function - correctly - or if i should just make the $db var 'global' within the quote_smart function itself - now that PHP is 5.4.

 

FYI: Yes, the objective is to rewrite all this code with PDO and prepared statements but need to get this up, quickly, with temp fix due to sudden issues due to host upgrade.

 

Would really appreciate some guidance on this one - thx!

Obviously global is the quick answer since you wouldn't have to make changes to every line that makes this call.  Of course many out there do not like global, but if it's your solution for the time-being I don't see the problem.

if the code is going to be redone using PDO, why did you or someone else take the time to switch to mysqli first? just because the mysql functions are depreciated does't mean that they still don't work. you could have safely ignored/suppressed the depreciated error on the mysql_connect() statement.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.