Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Sql{
- public $password = '****';
- public $user = '****';
- public $database = '****';
- public $host = 'localhost';
- var $querydb;
- public $response;
- function Connect_db($query, $dowhile = false){
- /*ini_set('display_errors', 1); ini_set('error_reporting', E_ALL);*/
- // подключаемся к серверу
- $link = mysqli_connect($this->host, $this->user, $this->password, $this-
- >database)
- or die(trim("Error") . mysqli_error($link));
- $this->querydb = $query;
- $result = mysqli_query($link, $this->querydb) or die();
- if($result)
- {
- unset($this->response);
- if($dowhile == true){
- while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
- //return $row;
- $this->response[] = $row;
- }
- }
- else{
- $row = mysqli_fetch_array($result, MYSQLI_ASSOC);
- $this->response = $row;
- }
- return $this->response;
- }
- // закрываем подключение
- mysqli_free_result($row);
- mysqli_close($link);
- }
- }
- $sql = new Sql;
- $duck = $sql->Connect_db("SELECT * FROM base_data LIMIT 0, 99",true);
- $data = array("company"=>"HeaSoft", "copyright"=>"© 2017, HeaSoft",
- "news"=>$duck);
- echo json_encode($data);
- ?>
- $link = mysqli_connect($this->host, $this->user, $this->password, $this->database)
- or trigger_error(mysqli_connect_error());
- mysqli_set_charset($link, 'utf8');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement