query('SELECT * FROM someplace'); // Get an array of items: $result = $db->get(); print_r($result); // Optional fetch modes (1 and 2) $db->setFetchMode(1); // Get a single item: $result = $db->get('field'); print_r($result); What you do with displaying the array result is up to you! ---------------------------------------- */ class DB { /** * @var The mode to return results, defualt is MYSQLI_BOTH, use setFetchMode() to change. */ private $fetchMode = MYSQLI_BOTH; /** * @desc Creates the MySQLi object for usage. * * @param $db Required connection params. */ public function __construct($db) { $this->mysqli = new mysqli($db['host'], $db['user'], $db['pass'], $db['table']); if (mysqli_connect_errno()) { printf("Connection failed: %s\n", mysqli_connect_error()); exit; } } /** * @desc Optionally set the return mode. * * @param $type The mode: 1 for MYSQLI_NUM, 2 for MYSQLI_ASSOC, default is MYSQLI_BOTH */ public function setFetchMode($type) { switch($type) { case 1: $this->fetchMode = MYSQLI_NUM; break; case 2: $this->fetchMode = MYSQLI_ASSOC; break; default: $this->fetchMode = MYSQLI_BOTH; break; } } /** * @desc Simple preparation to clean the SQL/Setup result Object. * * @param SQL statement * @return */ public function query($SQL) { $this->SQL = $this->mysqli->real_escape_string($SQL); $this->result = $this->mysqli->query($SQL); if ($this->result == true) { return true; } else { printf("Problem with SQL: %s\n", $this->SQL); exit; } } /** * @desc Get the results * * @param $field Select a single field, or leave blank to select all. * @return */ public function get($field = NULL) { if ($field == NULL) { /** Grab all the data */ $data = array(); while ($row = $this->result->fetch_array($this->fetchMode)) { $data[] = $row; } } else { /** Select the specific row */ $row = $this->result->fetch_array($this->fetchMode); $data = $row[$field]; } /** Make sure to close the result Set */ $this->result->close(); return $data; } /** * @desc Returns the automatically generated insert ID * This MUST come after an insert Query. */ public function id() { return $this->mysqli->insert_id; } /** * @desc Automatically close the connection when finished with this object. */ public function __destruct() { $this->mysqli->close(); } }