0

This code for some reason isn't compatible with PHP 7

function sitaData()
{
    global $sitetitle_en,$sitetitle_ar,$sitekeywords,$sitedescription,$maintenance;
    mysqli_query("set names utf8");
    $query="select * from sitedata";
    $res=mysqli_query($query);
    if(mysqli_num_rows($res)>0)
    {
        $record=mysqli_fetch_array($res);
        $sitetitle_en=$record['sitetitle_en'];
        $sitetitle_ar=$record['sitetitle_ar'];
        $sitekeywords=$record['sitekeywords'];
        $sitedescription=$record['sitedescription'];
        $maintenance=$record['maintenance'];
    }

}

what am I missing?

2 Answers2

1

Your code was probably converted from mysql_*() functions to mysqli_*() functions. The main difference between the two is that you have to explicitly pass mysqli connection identifier (the result of mysqli_connect()) to each mysqli_query() call. So at first you need to establish a connection (either in the function sitaData() or somewhere else and pass it to the function as parameter), and then you'll need to add the connection as the first parameter of mysqli_query().

E.g. mysqli_query($connection, "set names utf8");, $res=mysqli_query($connection, $query);

Jirka Hrazdil
  • 3,983
  • 1
  • 14
  • 17
0
$conn= mysqli_connect('localhost','username','password','database');     
function sitaData()
 {
global $sitetitle_en,$sitetitle_ar,$sitekeywords,$sitedescription,$maintenance;
mysqli_query($conn,"set names utf8");
$query="select * from sitedata";
$res=mysqli_query($conn,$query);
if(mysqli_num_rows($res)>0)
{
    $record=mysqli_fetch_array($res,MYSQLI_ASSOC);
    $sitetitle_en=$record['sitetitle_en'];
    $sitetitle_ar=$record['sitetitle_ar'];
    $sitekeywords=$record['sitekeywords'];
    $sitedescription=$record['sitedescription'];
    $maintenance=$record['maintenance'];
}

}

try this.