Function to get rows from database
Your code will work, of course, but you go to a lot of trouble to grind the result set into an array when that capability is already available. Mysqli would provide the fetch_all() function if you had the mysqlnd drivers available; fortunately, PDO has provided it since PHP 5.1.

You will need to create a PDO connection with

$dsn = "mysql:host=" . $hostname . ";dbname=" . $dbname . ";";
$dbh = new PDO($dsn, $dbuser, $dbpass);


then your function would be

function gd($query)
{
    global $dbh;
    $result = $dbh-&gt;query($query);
    $array = $result-&gt;fetchAll(PDO::FETCH_NUM);  // fetchAll() does the same as most of your original code
    return $array;
}