Simple static method written in PHP which reads the data from the customers table of a MySQL
Example of a simple static method written in PHP, which reads the data from the customers table of a MySQL database and returns them as an array.
/**
* The method returns the list of all customers, sorted by name
*
* @return (array) The list of all customers, sorted by name
*/
public static function getCustomerList() {
$customers = array();
$db_mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$sql = "SELECT * FROM customers ORDER BY name";
$result = $db_mysqli->query($sql);
if ($result != null) {
while ($row = mysqli_fetch_array($result)) {
$customers[] = $row;
}
$result->close();
}
$db_mysqli->close();
return $customers;
}