1
0

mysqlClass.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. include_once('mysql.php');
  3. class mysqlClass extends mysql{
  4. protected function connect()
  5. {
  6. $this->errormsg = '';
  7. if(!function_exists('mysql_connect'))exit('不支持mysql_connect的php扩展');
  8. $this->conn = @mysql_connect($this->db_host,$this->db_user, $this->db_pass);
  9. $msg = $this->error();
  10. if($msg){
  11. $this->conn = null;
  12. $this->errormsg = $msg;
  13. }else{
  14. $this->selectdb($this->db_base);
  15. $this->query("SET NAMES 'utf8'");
  16. }
  17. }
  18. protected function selectdb($name)
  19. {
  20. $this->basename = $name;
  21. @mysql_select_db($name, $this->conn);
  22. $msg = $this->error();
  23. if($msg){
  24. $this->errormsg = $msg;
  25. }
  26. }
  27. protected function querysql($sql)
  28. {
  29. return mysql_query($sql,$this->conn);
  30. }
  31. public function fetch_array($result, $type = 0)
  32. {
  33. $result_type = ($type==0)?MYSQL_ASSOC:MYSQL_NUM;
  34. return mysql_fetch_array($result, $result_type);
  35. }
  36. public function insert_id()
  37. {
  38. return mysql_insert_id();
  39. }
  40. protected function starttran()
  41. {
  42. $this->query('BEGIN');
  43. }
  44. protected function endtran($bo)
  45. {
  46. if(!$bo){
  47. $this->query('ROLLBACK');
  48. }else{
  49. $this->query('COMMIT');
  50. }
  51. }
  52. public function getalltable_old()
  53. {
  54. @$result = mysql_list_tables($this->basename);
  55. while($row = mysql_fetch_row($result)) {
  56. $arr[]=$row[0];
  57. }
  58. return $arr;
  59. }
  60. public function getallfields($table)
  61. {
  62. $sql = 'select * from '.$table.' limit 0,0';
  63. $row = $this->query($sql);
  64. $scount = mysql_num_fields($row);
  65. for($i=0; $i<$scount; $i++){
  66. $arr[] = mysql_field_name($row, $i);
  67. }
  68. return $arr;
  69. }
  70. public function error()
  71. {
  72. return mysql_error();
  73. }
  74. public function close()
  75. {
  76. return @mysql_close($this->conn);
  77. }
  78. }
粤ICP备19079148号