Advertisement
Guest User

Untitled

a guest
May 18th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. <?php
  2. Class MySQL
  3. {
  4. private $sqlhost="localhost";
  5. private $sqluser="chaosscr";
  6. private $sqlpass="a1293";
  7. public $sqldb="pastebin";
  8. protected $mysql;
  9. function __construct()
  10. {
  11. $this->mysql=mysql_connect($this->sqlhost,$this->sqluser,$this->sqlpass) or $this->error();
  12. if($this->sqldb)
  13. mysql_select_db($this->sqldb,$this->mysql) or $this->error();
  14. }
  15. public function close()
  16. {
  17. if(!mysql_close($this->mysql))
  18. $this->error();
  19. else
  20. return 1;
  21. }
  22. protected function error()
  23. {
  24. die(printf("<br /><b>MySQL ERROR</b>: %s (%d)",mysql_error(),mysql_errno()));
  25. }
  26. public function is_db_empty($db="")
  27. {
  28. if($db=="")
  29. $db=$this->sqldb;
  30. $tables=mysql_query("show tables from `$db`",$this->mysql);
  31. $intable="Tables_in_$db";
  32. while($table=@mysql_fetch_array($tables))
  33. $tablelist[]=$table[$intable];
  34. if(!isset($tablelist[0]))
  35. return 1;
  36. else
  37. return 0;
  38. }
  39. public function list_all()
  40. {
  41. $dbs=$this->list_dbs();
  42. for($a=0;$dbs[$a];$a++)
  43. {
  44. if($this->is_db_empty($dbs[$a]))
  45. $dbs[$dbs[$a]]=$dbs[$a];
  46. else
  47. $dbs[$dbs[$a]]=$this->list_tables($dbs[$a]);
  48. unset($dbs[$a]);
  49. }
  50. return $dbs;
  51. }
  52. public function list_dbs()
  53. {
  54. $dbs=mysql_query("show databases",$this->mysql) or $this->error();
  55. while($db=mysql_fetch_array($dbs))
  56. $dblist[]=$db['Database'];
  57. return $dblist;
  58. }
  59. public function list_tables($db="")
  60. {
  61. if($db=="")
  62. $db=$this->sqldb;
  63. $tables=mysql_query("show tables from `$db`",$this->mysql) or $this->error();
  64. $intable="Tables_in_$db";
  65. while($table=mysql_fetch_array($tables))
  66. $tablelist[]=$table[$intable];
  67. return $tablelist;
  68. }
  69. public function query($query)
  70. {
  71. return mysql_query($query,$this->mysql);
  72. }
  73. public function sdb($newdb)
  74. {
  75. mysql_select_db($newdb,$this->mysql) or $this->error();
  76. $this->sqldb=$newdb;
  77. }
  78. public function select($query)
  79. {
  80. $query=mysql_query($query,$this->mysql) or $this->error();
  81. while($row=mysql_fetch_array($query))
  82. for($a=0;$row[$a];$cont[]=$row[$a],$a++);
  83. return $cont;
  84. }
  85. }
  86. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement