n1concepts Posted October 20, 2014 Share Posted October 20, 2014 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! Quote Link to comment https://forums.phpfreaks.com/topic/291936-problem-with-function-using-mysqli_real_escape_string/ Share on other sites More sharing options...
requinix Posted October 20, 2014 Share Posted October 20, 2014 Quickly? Maybe global. I'd probably just pass it into the function though. Quote Link to comment https://forums.phpfreaks.com/topic/291936-problem-with-function-using-mysqli_real_escape_string/#findComment-1494211 Share on other sites More sharing options...
ginerjm Posted October 20, 2014 Share Posted October 20, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/291936-problem-with-function-using-mysqli_real_escape_string/#findComment-1494259 Share on other sites More sharing options...
mac_gyver Posted October 20, 2014 Share Posted October 20, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/291936-problem-with-function-using-mysqli_real_escape_string/#findComment-1494292 Share on other sites More sharing options...
ginerjm Posted October 20, 2014 Share Posted October 20, 2014 Deprecated. Deprecated! Quote Link to comment https://forums.phpfreaks.com/topic/291936-problem-with-function-using-mysqli_real_escape_string/#findComment-1494293 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.