mysqliClass.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. $roboll = $this->conn->query($sql);
  20. if(!$roboll)$this->setError($this->conn->error, $sql);
  21. return $roboll;
  22. }
  23. public function fetch_array($result, $type = 0)
  24. {
  25. $result_type = ($type==0)?MYSQLI_ASSOC:MYSQLI_NUM;
  26. return $result->fetch_array($result_type);
  27. }
  28. public function insert_id()
  29. {
  30. return $this->conn->insert_id;
  31. }
  32. protected function starttran()
  33. {
  34. $this->conn->autocommit(FALSE);
  35. }
  36. protected function endtran($bo)
  37. {
  38. if(!$bo){
  39. $this->conn->rollback();
  40. }else{
  41. $this->conn->commit();
  42. }
  43. }
  44. public function getallfields($table)
  45. {
  46. $sql = 'select * from '.$table.' limit 0,0';
  47. $result = $this->query($sql);
  48. if(!$result)return array();
  49. $finfo = $result->fetch_fields();
  50. foreach ($finfo as $val) {
  51. $arr[] = $val->name;
  52. }
  53. return $arr;
  54. }
  55. public function close()
  56. {
  57. if($this->conn==null)return;
  58. return $this->conn->close();
  59. }
  60. }
粤ICP备19079148号