Advertisement
Guest User

Untitled

a guest
Aug 25th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. <?php
  2. class Sql{
  3.  
  4.  
  5. public $password = '****';
  6. public $user = '****';
  7. public $database = '****';
  8. public $host = 'localhost';
  9.  
  10.  
  11. var $querydb;
  12. public $response;
  13.  
  14. function Connect_db($query, $dowhile = false){
  15.  
  16. /*ini_set('display_errors', 1); ini_set('error_reporting', E_ALL);*/
  17.  
  18. // подключаемся к серверу
  19. $link = mysqli_connect($this->host, $this->user, $this->password, $this-
  20. >database)
  21. or die(trim("Error") . mysqli_error($link));
  22. $this->querydb = $query;
  23.  
  24. $result = mysqli_query($link, $this->querydb) or die();
  25.  
  26. if($result)
  27. {
  28.  
  29. unset($this->response);
  30.  
  31. if($dowhile == true){
  32. while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
  33.  
  34.  
  35.  
  36. //return $row;
  37.  
  38. $this->response[] = $row;
  39. }
  40.  
  41.  
  42. }
  43. else{
  44. $row = mysqli_fetch_array($result, MYSQLI_ASSOC);
  45. $this->response = $row;
  46. }
  47.  
  48. return $this->response;
  49. }
  50.  
  51. // закрываем подключение
  52. mysqli_free_result($row);
  53. mysqli_close($link);
  54. }
  55.  
  56. }
  57.  
  58.  
  59. $sql = new Sql;
  60. $duck = $sql->Connect_db("SELECT * FROM base_data LIMIT 0, 99",true);
  61. $data = array("company"=>"HeaSoft", "copyright"=>"© 2017, HeaSoft",
  62. "news"=>$duck);
  63.  
  64. echo json_encode($data);
  65. ?>
  66.  
  67. $link = mysqli_connect($this->host, $this->user, $this->password, $this->database)
  68. or trigger_error(mysqli_connect_error());
  69.  
  70. mysqli_set_charset($link, 'utf8');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement