Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- final class MySQL
- {
- private $link;
- private $numMySQL;
- public function __construct()
- {
- $arr_host = explode(',', $host);
- $bd_host = (count($arr_host) > 1) ? $arr_host[mt_rand(0, count($arr_host) - 1)] : $arr_host[0];
- $this->numMySQL = 0;
- $this->link = mysqli_connect($host, $user, $pass, $db_name);
- if (mysqli_connect_errno($this->link)) {
- trigger_error("Нет соединения с MySQL");
- }
- if (!mysqli_ping($this->link)) {
- $bd_host = (count($arr_host) > 1) ? $arr_host[mt_rand(0, count($arr_host) - 1)] : $arr_host[0];
- $this->link = mysqli_connect($host, $user, $pass, $db_name);
- }
- mysqli_set_charset($this->link, 'utf8');
- }
- public function query($sql)
- {
- $this->numMySQL++;
- $resource = mysqli_query($this->link, $sql);
- if ($resource) {
- if (is_object($resource)) {
- $i = 0;
- $data = array();
- while ($result = mysqli_fetch_assoc($resource)) {
- $data[$i] = $result;
- $i++;
- }
- mysqli_free_result($resource);
- $query = new stdClass();
- $query->row = isset($data[0]) ? $data[0] : array();
- $query->rows = $data;
- $query->num_rows = $i;
- unset($data);
- return $query;
- } else {
- $query = new stdClass();
- $query->row = array();
- $query->rows = array();
- $query->num_rows = 0;
- return $query;
- }
- } else {
- $query = new stdClass();
- $query->row = array();
- $query->rows = array();
- $query->num_rows = 0;
- return $query;
- }
- }
- public function __destruct()
- {
- mysqli_close($this->link);
- }
- }
- ?>
Add Comment
Please, Sign In to add comment