mysqliClass.php 1.4 KB

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