How to convert MySQL query to PHP code
Try this:
$query=$this->db->query("SELECT A.*, B.* FROM (SELECT A.* FROM DriversInfo as A, InvoiceQueue as B WHERE A.CreateTime = B.DriverCreateTime AND B.Error <> 1 GROUP BY A.CreateTime UNION SELECT DISTINCT A.* FROM DriversInfo as A, OrderInfo as B WHERE A.CreateTime = B.DriverKey AND B.Invoice <> '0') as A LEFT JOIN DriversDoc as B on A.CreateTime = B.DriverCreateTime WHERE B.DriversLicense is null OR B.CarRegistration is null OR B.BizCertificate is null OR B.Insurance is null;");
$qry = "SELECT A.*, B.* FROM (SELECT A.* FROM DriversInfo as A, InvoiceQueue as B WHERE A.CreateTime = B.DriverCreateTime AND B.Error <> 1 GROUP BY A.CreateTime UNION SELECT DISTINCT A.* FROM DriversInfo as A, OrderInfo as B WHERE A.CreateTime = B.DriverKey AND B.Invoice <> '0') as A LEFT JOIN DriversDoc as B on A.CreateTime = B.DriverCreateTime WHERE B.DriversLicense is null OR B.CarRegistration is null OR B.BizCertificate is null OR B.Insurance is null;";$query = $this->db->query($qry);$result = $query->result_array();
<?php$servername = "localhost";$username = "username";$password = "password";$dbname = "myDB";// Create connection$conn = new mysqli($servername, $username, $password, $dbname);// Check connectionif ($conn->connect_error) { die("Connection failed: " . $conn->connect_error);}$sql = "SELECT A.*, B.*FROM (SELECT A.* FROM DriversInfo as A, InvoiceQueue as B WHERE A.CreateTime = B.DriverCreateTime AND B.Error <> 1 GROUP BY A.CreateTime UNION SELECT DISTINCT A.* FROM DriversInfo as A, OrderInfo as B WHERE A.CreateTime = B.DriverKey AND B.Invoice <> '0') as ALEFT JOIN DriversDoc as Bon A.CreateTime = B.DriverCreateTimeWHERE B.DriversLicense is nullOR B.CarRegistration is nullOR B.BizCertificate is nullOR B.Insurance is null";$result = $conn->query($sql);if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { //displaying row }} else { echo "0 results";}$conn->close();?>