Jump to content

Mysqli from mysql


FUNKAM35
Go to solution Solved by VanityCrush,

Recommended Posts

$total_results = mysqli_result(mysqli_query("SELECT COUNT(*) as Num  FROM property  WHERE  $where "),0) ;
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num  FROM property  WHERE  $where "),0) ;

Hi, Please can anyone help

 

I have changed MySQL_

 

to mysqli_

 

but I am getting fatal error on above line, please can anyone help

Thanks

Link to comment
Share on other sites

  • Solution

Hi there,

 

mysql_query is deprecated and it will be removed on future PHP versions. Use mysqli_query instead.

 

mysqli_query takes two parameters - the database connection and the actual query, therefore you have to include the database connection file in your code.

 

For example :

$dbCon = mysqli_connect("localhost", "root", "password", "database_name") or die(mysqli_error());

As you can see, I am storing the database connection in a variable.

 

To implement this into mysqli_query we now need to store the actual query in a variable (you could also write the full query as the second parameter but it will make your code less readable)

$sql = "SELECT COUNT(*) as Num  FROM property  WHERE  $where "; 

Now to implement this with mysqli:

$query = mysqli_query($dbCon, $sql); 

For mysql_result you can use the below function which is basically a mysqli_result:

function mysqli_result($res,$row=0,$col=0) { 
    $numrows = mysqli_num_rows($res); 
    if ($numrows && $row <= ($numrows-1) && $row >=0) {
        mysqli_data_seek($res,$row);
        $resrow = (is_numeric($col)) ? mysqli_fetch_row($res) : mysqli_fetch_assoc($res);
        if (isset($resrow[$col])) {
            return $resrow[$col];
        }
    }
    return false;
}

After all this, your line should look like:

$total_results = mysqli_result($query, 0);

Hope this helps in a way or another.

  • Like 1
Link to comment
Share on other sites

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.