I'm using PHP as backend and MySql database, I have this many-to-many relationship 

```
Drivers{
id,
name
}

Units{
id,
name
}

Driver_Units{
id,
unitId,
driverId
}

```

When i run script get driver details by driver id, i want to have json response like this

```
{
firstName: driver_firstName,
lastName: driver_lastName
units: [unitObject1, unitObject2, unitObject...]
}

```

So i want to have driver object and array of his unit objects in one response.
I'm beginner at PHP and MySql and i would like someone good at it to help me with this script and tell me is my current script "good" and how i can fetch array of unit objects as part of this response and generally how i can improve this script.

**EDIT:** 

I tried solution that i got as answer in this question and i have code like this

```
<?php
require_once '../../dbConnect.php';

$driver_id = '%';

if (isset($_GET['driver_id'])) {
    $driver_id = $_GET['driver_id'];
}

$driver_id = 3; //hardcode to test it

$stmt = $mysqli->prepare("
    SELECT d.firstName, d.lastName, u.make, u.model FROM drivers AS d
    LEFT JOIN drivers_units AS du ON d.driver_id = du.driverId
    LEFT JOIN units AS u ON u.unit_id = du.unitId
    WHERE d.driver_id = ?");

if($stmt) {
    $stmt->bind_param("i", $driver_id);
    $stmt->execute();
    $stmt->bind_result($first_name, $last_name, $unit_make, $unit_model);
    $driver = null;
    while ($stmt->fetch()) {
        if (empty($driver)) { // On first row populate all the driver info
            $driver = array(
                'firstName' => $first_name,
                'lastName' => $last_name,
                'units' => array()
            );
        }
        if ($unit_name) {
            $driver['units'][] = array(
                'make' => $unit_make,
                'model' => $unit_model
            );
        }
    }

    $mysqli->close();
    echo $json_response = json_encode($driver); 
}

?>

```

But this code returns me a NULL, so it's like i don't get anything from this query.