[RESOLVED] mysqli help
Results 1 to 3 of 3

Thread: [RESOLVED] mysqli help

  1. #1
    Hockey Stats Man
    Join Date
    Nov 2006
    Location
    FSJ, BC, Canada
    Posts
    297

    resolved [RESOLVED] mysqli help

    I am converting all my mysql stuff to mysqli and so far going pretty well...

    i am having an issue with the code below where it gives me the following error
    Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in

    I didnt write this part of the code originally. i have tried taking it out and get alot more errors and taking different pieces of it out as well. The page loads and all of its data. should i make it so if null is given do something if not null do something

    Code:
    if (!isset($config_connection) || !$config_connection) {
    	$config_connection = mysqli_connect("$hostname", "$user", "$password", "$db");
    }
    
    if ( !function_exists('_safe'))
    {
    	function _safe( $str = '' )
    	{
    		if ( !$str ) return;
    		
    		if ( !is_numeric($str) ) {
    				
    			if (get_magic_quotes_gpc())
    			$str = stripslashes($str);
    			$str = mysqli_real_escape_string($config_connection, $str);
                            var_dump($str);
    		}
    
    		return $str;
    	}
    }
    mike carter

  2. #2
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,432
    The problem is that in this function:

    PHP Code:
        function _safe$str '' )
        {
            if ( !
    $str ) return;
            
            if ( !
    is_numeric($str) ) {
                    
                if (
    get_magic_quotes_gpc())
                
    $str stripslashes($str);
                
    $str mysqli_real_escape_string($config_connection$str);
                            
    var_dump($str);
            }

            return 
    $str;
        } 
    there is no such variable called $config_connection, thus PHP "invents" the variable at the point where you attempted to use it and assigns it a default value of null. Either pass in the MySQLi object, or do the escaping outside of this function.

  3. #3
    Hockey Stats Man
    Join Date
    Nov 2006
    Location
    FSJ, BC, Canada
    Posts
    297
    thanks for the help and got it fixed... i did escaping outside of the function and it worked... also just removing the line mysqli_real_escape_string also worked.. but i went with your method..

    thanks for the help
    mike carter

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •