I am trying to delete from table1 if ID does not exist in table2 in Mysql.
When using sql query in Phpmyadmin
DELETE t1 FROM db.table1 t1 LEFT JOIN db.table2 t2 ON t1.id = t2.id WHERE t2.id IS NULL
it works perfectly deleting from table1 rows not found in table2 !
However when using same sql in PHP as
mysqli_query($connection,"DELETE t1 FROM db.table1 t1 LEFT JOIN db.table2 t2 ON t1.id = t2.id WHERE t2.id IS NULL") or die(mysqli_error($connection));
it throws error No database selected . I have verified and my connections are defined properly with host,username and password.
$connection = @mysqli_connect($host,$username,$password);
I do not think that $connection is problem as there are other queries before/after it which all work perfectly ! What am I doing wrong ?