You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

178 lines
3.7 KiB

  1. <?php
  2. /**
  3. *
  4. * ============================================================================
  5. * * 版权所有 蜘蛛出行 * *
  6. * 网站地址: http://www.zhizhuchuxing.com
  7. * ----------------------------------------------------------------------------
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
  9. * 使用;不允许对程序代码以任何形式任何目的的再发布。
  10. * ============================================================================
  11. * Author By: 倪宗锋
  12. * PhpStorm DbTable.php
  13. * Create By 2016/11/8 12:16 $
  14. */
  15. namespace Base\Tool;
  16. use Util\Util\MyPDO;
  17. class DbTable
  18. {
  19. public $db;
  20. public $tab;
  21. public $pdo;
  22. public function __construct()
  23. {
  24. $this->pdo = MyPDO::getInstance($this->db);
  25. }
  26. /**
  27. * Function Description:获取一条记录
  28. * Function Name: fetchRow
  29. * @param $strSql
  30. *
  31. * @return mixed|string
  32. *
  33. * @author 倪宗锋
  34. */
  35. public function fetchRow($strSql)
  36. {
  37. return $this->pdo->fetchRow($strSql);
  38. }
  39. /**
  40. * Function Description:获取多条记录
  41. * Function Name: fetchAll
  42. * @param $strSql
  43. *
  44. * @return array|mixed|string
  45. *
  46. * @author 倪宗锋
  47. */
  48. public function fetchAll($strSql)
  49. {
  50. return $this->pdo->fetchAll($strSql);
  51. }
  52. /**
  53. * Function Description:获取第一条记录中的第一个字段
  54. * Function Name: fetchOne
  55. * @param $strSql
  56. *
  57. * @return string
  58. *
  59. * @author 倪宗锋
  60. */
  61. public function fetchOne($strSql)
  62. {
  63. return $this->pdo->fetchOne($strSql);
  64. }
  65. /**
  66. * Function Description:更新
  67. * Function Name: update
  68. * @param $arrayDataValue array 字段与值
  69. * @param string $where string where条件
  70. *
  71. * @return int
  72. *
  73. * @author 倪宗锋
  74. */
  75. public function update($arrayDataValue, $where = '')
  76. {
  77. return $this->pdo->update($this->tab, $arrayDataValue, $where);
  78. }
  79. /**
  80. * Function Description:插入
  81. * Function Name: insert
  82. * @param $arrayDataValue array 字段与值
  83. *
  84. * @return int
  85. *
  86. * @author 倪宗锋
  87. */
  88. public function insert($arrayDataValue)
  89. {
  90. return $this->pdo->insert($this->tab, $arrayDataValue);
  91. }
  92. /**
  93. * Replace 覆盖方式插入
  94. *
  95. * @param Array $arrayDataValue 字段与值
  96. * @return Int
  97. */
  98. public function replace($arrayDataValue)
  99. {
  100. return $this->pdo->replace($this->tab, $arrayDataValue);
  101. }
  102. /**
  103. * Delete 删除
  104. *
  105. * @param String $where 条件
  106. * @return Int
  107. */
  108. public function delete($where = '')
  109. {
  110. return $this->pdo->delete($this->tab, $where);
  111. }
  112. /**
  113. * Function Description:execSql 执行SQL语句
  114. * Function Name: execSql
  115. * @param $strSql
  116. *
  117. * @return int
  118. *
  119. * @author 倪宗锋
  120. */
  121. public function execSql($strSql)
  122. {
  123. return $this->pdo->execSql($strSql);
  124. }
  125. /**
  126. * beginTransaction 事务开始
  127. */
  128. public function beginTransaction()
  129. {
  130. $this->pdo->beginTransaction();
  131. }
  132. /**
  133. * commit 事务提交
  134. */
  135. public function commit()
  136. {
  137. $this->pdo->commit();
  138. }
  139. /**
  140. * rollback 事务回滚
  141. */
  142. public function rollback()
  143. {
  144. $this->pdo->rollback();
  145. }
  146. /**
  147. * transaction 通过事务处理多条SQL语句
  148. * 调用前需通过getTableEngine判断表引擎是否支持事务
  149. *
  150. * @param array $arraySql
  151. * @return Boolean
  152. */
  153. public function execTransaction($arraySql)
  154. {
  155. return $this->pdo->execTransaction($arraySql);
  156. }
  157. }