mysqliClass.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. include_once('mysql.php');
  3. class mysqliClass extends mysql{
  4. protected function connect()
  5. {
  6. $this->errormsg = '';
  7. if(!class_exists('mysqli'))exit('操作数据库的php的扩展mysqli不存在');
  8. $this->conn = @new mysqli($this->db_host,$this->db_user, $this->db_pass, $this->db_base);
  9. if (mysqli_connect_errno()) {
  10. $this->conn = null;
  11. $this->errormsg = mysqli_connect_error();
  12. }else{
  13. $this->selectdb($this->db_base);
  14. $this->conn->query("SET NAMES 'utf8'");
  15. }
  16. }
  17. protected function querysql($sql)
  18. {
  19. return $this->conn->query($sql);
  20. }
  21. public function fetch_array($result, $type = 0)
  22. {
  23. $result_type = ($type==0)?MYSQLI_ASSOC:MYSQLI_NUM;
  24. return $result->fetch_array($result_type);
  25. }
  26. public function insert_id()
  27. {
  28. return $this->conn->insert_id;
  29. }
  30. protected function starttran()
  31. {
  32. $this->conn->autocommit(FALSE);
  33. }
  34. protected function endtran($bo)
  35. {
  36. if(!$bo){
  37. $this->conn->rollback();
  38. }else{
  39. $this->conn->commit();
  40. }
  41. }
  42. public function getallfields($table)
  43. {
  44. $sql = 'select * from '.$table.' limit 0,0';
  45. $result = $this->query($sql);
  46. if(!$result)return array();
  47. $finfo = $result->fetch_fields();
  48. foreach ($finfo as $val) {
  49. $arr[] = $val->name;
  50. }
  51. return $arr;
  52. }
  53. public function error()
  54. {
  55. return 'mysqliError:'.$this->conn->error;
  56. }
  57. public function close()
  58. {
  59. if($this->conn==null)return;
  60. return $this->conn->close();
  61. }
  62. }
粤ICP备19079148号