mysqliClass.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. $finfo = $result->fetch_fields();
  46. foreach ($finfo as $val) {
  47. $arr[] = $val->name;
  48. }
  49. return $arr;
  50. }
  51. public function error()
  52. {
  53. return 'mysqliError:'.$this->conn->error;
  54. }
  55. public function close()
  56. {
  57. if($this->conn==null)return;
  58. return $this->conn->close();
  59. }
  60. }