mysqliClass.php 1.6 KB

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