-1

UPD: CLOSED. Duplicate found and typos in my original question

I am using this code and I want to get a message if there is an error with my SQL query :

$Db = mysqli_init();
$Db->options(MYSQLI_OPT_LOCAL_INFILE, true);
$Db->real_connect($servername, $username, $password, $dbname, 3306);

// Creation of first SQL query
$sql = ('select sum('.$metric1.') as t1metric from '.$table1.' WHERE '.$date1.' between "'.$start_date.'" AND "'.$end_date.'"');
$query = $Db->query($sql);

if ($Db->error) 
{
    printf("Errormessage: %s\n", $Db->error);
}

and I receive this error when I run the php file :

Call to a member function query() on a non-object

Datacrawler
  • 2,780
  • 8
  • 46
  • 100

2 Answers2

2

use the following

$Db->query($sql); 

instead of

$mysqli->query($query);
Syed mohamed aladeen
  • 6,507
  • 4
  • 32
  • 59
Drop Shadow
  • 845
  • 3
  • 12
  • 28
1
$mysqli->query($query);

Replace with:

 $Db->query($query);
Shailesh Katarmal
  • 2,757
  • 1
  • 12
  • 15