国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

首頁 後端開發(fā) php教程 php pdo資料庫操作封裝類別程式碼

php pdo資料庫操作封裝類別程式碼

Jul 25, 2016 am 08:51 AM

  1. /**

  2. * ?????? PDO ??
  3. */
  4. class MysqlPdo {
  5. public static $PDOStatement = null;
  6. /**
  7. * ?????? ?? ???? ??
  8. * @var array
  9. * @access public
  10. */
  11. public static $config = array();
  12. /**
  13. * ?? ?? ?? ??
  14. * @var bool
  15. * @access public
  16. */
  17. public static $pconnect = false;
  18. /**
  19. * ?? ???
  20. * @var string
  21. * @access public
  22. */
  23. public static $error = '';
  24. /**
  25. * ??? ??, Pdo ???? ??? ????? ??????? ?? ???? ?????.
  26. * @var object
  27. * @access public
  28. */
  29. protected static $link;
  30. /**
  31. * ?????? ?? ??
  32. * @var bool
  33. * @access public
  34. */
  35. public static $connected = false;
  36. /**
  37. * ?????? ??
  38. * @var string
  39. * @access public
  40. */
  41. public static $dbVersion = null;
  42. /**
  43. * ?? SQL ?
  44. * @var string
  45. * @access public
  46. */
  47. public static $queryStr = ' ';
  48. /**
  49. * ????? ??? ???? ID
  50. * @var ??
  51. * @access public
  52. */
  53. public static $lastInsertId = null;
  54. /**
  55. * ??? ?? ??? ?? ?????.
  56. * @var ??
  57. * @access public
  58. */
  59. public static $numRows = 0;
  60. // ???? ??? ?
  61. public static $transTimes = 0;
  62. /**
  63. * ???,
  64. * @param $dbconfig ?????? ?? ?? ??, array('ServerName', 'UserName', 'Password', 'DefaultDb', 'DB_Port', 'DB_TYPE')
  65. */
  66. ?? ?? __construct($dbConfig=''){
  67. if (!class_exists('PDO') ) self::throw_Exception("???? ??: PDO");
  68. //????? ???? ??? ?? ??? ??? ?????
  69. if (!is_array($dbConfig)) {
  70. $dbConfig = ??(
  71. '??? ??' => DB_HOST,
  72. '??? ??' => DB_USER,
  73. '????' => DB_PWD,
  74. '??????' => DB_NAME,
  75. '??? ??' => ; DB_PORT,
  76. 'dbms' => DB_TYPE,
  77. 'dsn' => DB_TYPE.":host=".DB_HOST.";dbname=".DB_NAME
  78. );
  79. }
  80. if(empty($dbConfig['hostname'])) self::throw_Exception("?????? ??? ???? ??");
  81. self::$config = $dbConfig;
  82. if(empty( self:: $config['params'])) self::$config['params'] = array();
  83. /**************************************?? ???************ *******************************/
  84. if (!isset(self::$ link) ) {
  85. $configs = self::$config;
  86. if(self::$pconnect) {
  87. $configs['params'][constant('PDO::ATTR_PERSISTENT')] = true;
  88. }
  89. {
  90. self::$link = new PDO( $configs['dsn'], $configs['username'], $configs['password'],$configs[ 'params' ?? ]);
  91. } catch (PDOException $e) {
  92. self::throw_Exception($e->getMessage());
  93. }
  94. if(!self::$link ) {
  95. self::throw_Exception('PDO ?? ??');
  96. false ??;
  97. }
  98. self::$link->exec('SET NAMES '.DB_CHARSET);
  99. self: :$dbVersion = self::$link->getAttribute(constant("PDO::ATTR_SERVER_INFO"));
  100. // ??? ????? ??
  101. self::$connected = true;
  102. // ?????? ?? ?? ?? ?? ??
  103. unset($configs);
  104. }
  105. return self::$link;
  106. }
  107. /**
  108. * ?? ?? ??
  109. * @access ??
  110. */
  111. ?? ?? ?? () {
  112. self::$PDOStatement = null;
  113. }
  114. /************************/
  115. /* ?????? ??*/
  116. /************************/
  117. /**
  118. * ?? ?? ??? ????
  119. * @access ??
  120. * @return ??
  121. */
  122. ?? ?? getAll($sql=null) {
  123. if($sql != null)
  124. {
  125. self::query($sql) ;
  126. }
  127. //??? ?? ??
  128. $result = self::$PDOStatement->fetchAll(constant('PDO::FETCH_ASSOC'));
  129. return $result;
  130. }
  131. /**
  132. * ?? ?? ????
  133. * @access ??
  134. * @param string $sql SQL ??
  135. * @param ?? $seek ??? ??
  136. * @return ??
  137. */
  138. ?? ?? getRow($sql=null) {
  139. if($sql != null)
  140. {
  141. self::query($sql ) ;
  142. }
  143. // ?? ?? ??
  144. $result = self::$PDOStatement->fetch(constant('PDO::FETCH_ASSOC'),constant('PDO::FETCH_ORI_NEXT')) ;
  145. return $result;
  146. }
  147. /**
  148. * SQL ?? ???? ?? ?? ?? ??? ???? ??
  149. * @access ??
  150. * @param string $sql SQL ??
  151. * @return ??
  152. */
  153. ?? ?? doSql($sql='') {
  154. if(self::isMainIps($sql) ) {
  155. return self::execute($sql);
  156. }else {
  157. return self::getAll($sql);
  158. }
  159. }
  160. /**
  161. * ??? ID? ???? ???? ??? ??(?? ??? ???? ??)
  162. * @access ??
  163. * @param ?? $priId ?? ? ID
  164. * @param string $tables ??? ??? ??
  165. * @param string $fields ?? ??
  166. * @return ArrayObject ??? ???
  167. */
  168. ?? ?? findById($tabName,$priId,$fields='*'){
  169. $sql = 'SELECT %s FROM %s WHERE id=%d';
  170. self ??: : getRow(sprintf($sql, self::parseFields($fields), $tabName, $priId));
  171. }
  172. /**
  173. * 尋找記錄
  174. * @access function
  175. * @param string $tables 資料表名
  176. * @param mixed $where 查詢條件
  177. * @param string $fields 欄位名稱
  178. * @param string $order 排序
  179. * @param string $limit 取多少條資料
  180. * @param string $group 分組
  181. * @param string $having
  182. * @param boolean $lock 是否加鎖
  183. * @return ArrayObject
  184. */
  185. 靜態(tài)函數(shù) find($tables,$where="",$fields='*',$order=null,$limit=null,$group=null,$ having=null) {
  186. $sql = 'SELECT '.self::parseFields($fields)
  187. .' FROM '.$tables
  188. .self::parseWhere($where)
  189. .self::parseGroup($group)
  190. .self::parseHaving($having)
  191. .self::parseOrder( $order)
  192. .self::parseLimit($limit);
  193. $dataAll = self::getAll($sql);
  194. if(count($dataAll)==1){$rlt=$ dataAll[0];}else{$rlt=$dataAll;}
  195. return $rlt;
  196. }
  197. /**
  198. * 插入(單一)記錄
  199. * @access function
  200. * @param mixed $data 資料
  201. * @param string $table 資料表名
  202. * @return false | integer
  203. */
  204. function add($data,$table) {
  205. //過濾提交資料
  206. $data=self::filterPost($table,$data);
  207. foreach ($data as $key=>$val){
  208. if(is_array( $ val) && strtolower($val[0]) == 'exp') {
  209. $val = $val[1]; // 使用表達式 ???
  210. }elseif (is_scalar($val)){
  211. $val = self::fieldFormat($val);
  212. }else{
  213. //刪除複合物件
  214. 繼續(xù);
  215. }
  216. $data[$key] = $val;
  217. }
  218. $fields = array_keys($data);
  219. array_walk($fields, array($this, 'addSpecialChar'));
  220. $fieldsStr = implode(',', $fields);
  221. $values = array_values($data);
  222. $valuesStr = implode(',', $values);
  223. $sql = '插入'.$table.' ('.$fieldsStr.') VALUES ('.$valuesStr.')';
  224. return self::execute($sql);
  225. }
  226. /**
  227. * 更新記錄
  228. * @access function
  229. * @param mixed $sets 資料
  230. * @param string $table 資料表名
  231. * @param string $where 更新條件
  232. * @param string $limit
  233. * @param string $order
  234. * @return false | integer
  235. */
  236. 靜態(tài)函數(shù)update($sets,$table,$where,$limit=0,$order='') {
  237. $sets = self::filterPost($table,$sets);
  238. $sql = '更新「.$表」。 self::execute($sql );
  239. }
  240. /**
  241. * 儲存某個欄位的值
  242. * @access function
  243. * @param string $field 要儲存的欄位名稱
  244. * @param string $value 欄位值
  245. * @param string $ table 資料表
  246. * @param string $where 儲存條件
  247. * @param boolean $asString 欄位值是否為字串
  248. * @return void
  249. */
  250. 靜態(tài)函式setField($field, $value, $table, $condition="", $asString=false ) {
  251. //如果有'(' 視為SQL 指令更新否則更新欄位內容為純字串
  252. if(false === strpos($value,'(') || $asString) $value = '"'.$value .'"';
  253. $sql = '更新'.$table.' SET '.$field.'='.$value.self::parseWhere($condition);
  254. 回傳self::execute( $sql);
  255. }
  256. /**
  257. * 刪除記錄
  258. * @access function
  259. * @param mixed $where 為條件Map、Array或String
  260. * @param string $table 資料表名
  261. * @param string $limit
  262. * @param string $order
  263. * @return false | integer
  264. */靜態(tài)函式($where,$table,$limit='',$order='' ) {
  265. $sql = 'DELETE FROM '.$table.self::parseWhere($where).self::parseOrder($order).self::parseLimit($limit);
  266. 回傳self::執(zhí)行($sql);
  267. }
  268. /**
  269. ----------------------------------------------- -----------
  270. * 修改或儲存資料(僅用於單表操作)
  271. * 有主鍵ID則為修改,無主鍵ID則為增加
  272. * 修改記錄:
  273. ---------------------------------------------- ------------
  274. * @access function
  275. ---------------------------- ------------------------------
  276. * @param $tabName 表名
  277. * @param $aPost 提交表單的$_POST
  278. * @param $priId 主鍵ID
  279. * @param $aNot 要排除的一個字段或數(shù)組
  280. * @param $aCustom 自訂的數(shù)組,附加到資料庫中保存
  281. * @param $isExits 是否已經(jīng)存在存在:true, 不存在:false
  282. ------------------------------- ---------------------------
  283. * @return Boolean 修改或儲存是否成功
  284. -------- --------------------------------------------------
  285. */
  286. 函數(shù)saveOrUpdate($tabName, $aPost, $priId="", $aNot="", $aCustom="" , $isExits=false) {
  287. if(empty($tabName) || !is_array($aPost) || is_int($aNot)) return false;
  288. if(is_string($aNot) && !empty($aNot)) $aNot = array($aNot);
  289. if(is_array($aNot) && is_int(key ) ($aNot))) $aPost = array_diff_key($aPost, array_flip($aNot));
  290. if(is_array($aCustom) ) && is_string(key($aCustom))) $aPost = array_merge($aCustom))) $aPost = array_merge($aCustom))) $aPost = aPostge($aPost , $aCustom);
  291. if (empty($priId) && !$isExits) { // 新增
  292. $aPost = array_filter ($aPost, array($this, 'removeEmpty'));
  293. return self::add($aPost, $tabName);
  294. }else { //修改
  295. return self::update($aPost, $tabName, "id=".$priId);
  296. }
  297. }
  298. /**
  299. * 取得最近一次查詢的sql語句
  300. * @access function
  301. * @param
  302. * @return String 執(zhí)行的SQL
  303. */
  304. 靜態(tài)函數(shù)getLastSql() {
  305. $link = self::$link;
  306. if (!$link ) return false;
  307. 回傳self::$queryStr;
  308. }
  309. /* *
  310. * 取得最後插入的ID
  311. * @access function
  312. * @param
  313. * @return integer 最後插入時的資料ID
  314. */
  315. 靜態(tài)函式getLastInsId(){
  316. $link = self::$link;
  317. if ( !$link ) return false;
  318. 回傳self::$lastInsertId;
  319. }
  320. /**
  321. * 取得DB版本
  322. * @access function
  323. * @param
  324. * @return string
  325. */
  326. 靜態(tài)函數(shù)getDbVersion(){
  327. $link = self::$link;
  328. if ( !$link ) return false;
  329. return self::$dbVersion;
  330. }
  331. /**
  332. * 取得資料庫的表格資訊
  333. * @access function
  334. * @return array
  335. */
  336. static function getTables() {
  337. $info = array();
  338. if(self::query ("顯示表格")) {
  339. $result = self::getAll();
  340. foreach ($result as $key => $val) {
  341. $info[$key] = current( $ val);
  342. }
  343. }
  344. return $info;
  345. }
  346. /**
  347. * 取得資料表的欄位資訊
  348. * @access function
  349. * @return array
  350. */
  351. 靜態(tài)函數(shù)getFields($tableName) {
  352. //取得資料庫連線
  353. $link = self::$link;
  354. $sql = "SELECT
  355. ORDINAL_POSITION ,COLUMN_NAME, COLUMN_TYPE, DATA_TYPE,
  356. IF(ISNULL(CHARACTER_MAX ) AS MAXCHAR,
  357. IS_NULLABLE, COLUMN_DEFAULT, COLUMN_KEY, EXTRA, COLUMN_COMMENT
  358. FROM
  359. INFORMATION_SCH! ?? >self::$queryStr = sprintf($sql, $tableName);
  360. $sth = $link->prepare($sql);
  361. $sth->bindParam(':tabName', $ tableName);
  362. $sth->execute();
  363. $result = $sth->fetchAll(constant('PDO::FETCH_ASSOC'));
  364. $info = array();
  365. foreach ($ result as $key =>; $val) {
  366. $info[$val['COLUMN_NAME']] = array(
  367. 'postion' => $val['ORDINAL_POSITION'],
  368. 'name' => $val[ 'COLUMN_NAME'],
  369. 'type' => $val['COLUMN_TYPE'],
  370. 'd_type' => $val['DATA_TYPE'],
  371. 'length' => $val ['MAXCHAR'],
  372. 'notnull' => (strtolower($val['IS_NULLABLE']) == "否"),
  373. 'default' => $val['COLUMN_DEFAULT'],
  374. 'primary' => (strtolower($val['COLUMN_KEY']) == 'pri'),
  375. 'autoInc' => (strtolower($val['EXTRA']) == ' auto_increment' ),
  376. 'comment' => $val['COLUMN_COMMENT']
  377. );
  378. }
  379. //有錯誤則發(fā)送異常
  380. self::haveErrorThrowException(); return $info;
  381. }
  382. /**
  383. * 關閉資料庫
  384. * @access function
  385. */
  386. 靜態(tài)函式close() {
  387. self::$link = null;
  388. }
  389. / **
  390. * SQL指令安全過濾
  391. * @access function
  392. * @param string $str SQL指令
  393. * @return string
  394. */
  395. static function escape_string($str) {
  396. return addslashes($str);
  397. }
  398. /*************************/
  399. /* 內部操作方法*/
  400. /*************************/
  401. /**
  402. * 有錯誤拋出例外
  403. * @access function
  404. * @return
  405. */
  406. 靜態(tài)函式haveErrorThrowException() {
  407. $obj = 空(self::$PDOStatement) ? self::$link : self::$PDOStatement;
  408. $arrError = $obj->errorInfo();
  409. if($arrError[0] !== '00000') { // 有錯誤訊息
  410. self::$error = $arrError[0]."|".$arrError[2]. "
    [ SQL ] : ".self::$queryStr."
    ";
  411. self::throw_exception(self::$error);
  412. 回傳false;
  413. }
  414. //主要針對execute()方法發(fā)送例外狀況
  415. if(self::$queryStr=='' )self::throw_exception('查詢?yōu)榭?br>
    [ SQL 語句] :');
  416. }
  417. /**
  418. * where分析
  419. * @access function
  420. * @param mixed $where 查詢條件
  421. * @return string
  422. */
  423. 靜態(tài)函式parseWhere($where ) {
  424. $whereStr = '';
  425. if( is_string($where) || is_null($where)) {
  426. $whereStr = $where;
  427. }
  428. 回傳空($ whereStr)?'':' WHERE '.$whereStr;
  429. }
  430. /**
  431. * 訂單分析
  432. * @access 函數(shù)
  433. * @param mix $order 排除訂單
  434. * @return string
  435. */
  436. 靜態(tài)函數(shù)parseOrder($order) {
  437. $orderStr = '';
  438. if(is_array($order))
  439. $orderStr .= ' ORDER BY '.implode(',', $order);
  440. else if(is_string($order) && !empty($order))
  441. $orderStr .= ' ORDER BY '.$order;
  442. return $orderStr;
  443. }
  444. /**
  445. * 限制分析
  446. * @access 函數(shù)
  447. * @param string $limit
  448. * @return string
  449. */
  450. 靜態(tài)函數(shù)parseLimit($limit) {
  451. */
  452. 靜態(tài)函數(shù)parseLimit($limit) {
  453. $limitStr = '';
  454. if(is_array($limit) )) {
  455. if(count($limit)>1)
  456. $limitStr .= ' LIMIT '.$limit[0]. ' , '.$limit[1].' ';
  457. else
  458. $limitStr .= ' LIMIT '.$limit[0].' ';
  459. } else if(is_string($limit) && !empty($limit)) {
  460. $limitStr .= ' LIMIT '.$limit.' ';
  461. }
  462. 回傳$limitStr;
  463. }
  464. /**
  465. * ?? ??
  466. * @access ??
  467. * @param ?? $group
  468. * @return ???
  469. */
  470. ?? ?? parseGroup($group) {
  471. $groupStr = '';
  472. if(is_array($group))
  473. $groupStr .= ' GROUP BY '.implode(',', $group);
  474. else if(is_string($group) && !empty($group))
  475. $groupStr .= ' GROUP BY '.$group;
  476. empty($groupStr)?'':$groupStr;
  477. }
  478. /**
  479. * have分析
  480. * @access ??
  481. * @param string $having
  482. * @return string
  483. */
  484. ?? ??parseHaving($having) {
  485. $havingStr = '';
  486. if(is_string($having) && !empty($having))
  487. $havingStr .= ' HAVING '.$having;
  488. return $havingStr;
  489. }
  490. /**
  491. * ?? ??
  492. * @access ??
  493. * @param ?? $??
  494. * @return ???
  495. */
  496. function parseFields($fields) {
  497. if(is_array($fields)) {
  498. array_walk($fields, array($this, 'addSpecialChar'));
  499. $fieldsStr = implode(',', $fields);
  500. }else if(is_string($fields) && !empty($fields)) {
  501. if( false === strpos($fields,'`') ) {
  502. $fields =explode(',',$fields);
  503. array_walk($fields, array($this, 'addSpecialChar'));
  504. $fieldsStr = implode(',', $fields );
  505. }else {
  506. $fieldsStr = $fields;
  507. }
  508. }else $fieldsStr = '*';
  509. return $fieldsStr;
  510. }
  511. /**
  512. * ??? ???? ? ???? ?? ??
  513. * @access ??
  514. * @param ?? $? ??
  515. * @return ???
  516. */
  517. ??? ?? parseSets($sets) {
  518. $setsStr = '';
  519. if(is_array($sets)){
  520. foreach ($sets as $key=> $val){
  521. $key = self::addSpecialChar($key);
  522. $val = self::fieldFormat($val);
  523. $setsStr .= "$key = ".$val. ",";
  524. }
  525. $setsStr = substr($setsStr,0,-1);
  526. }else if(is_string($sets)) {
  527. $setsStr = $sets;
  528. }
  529. return $setsStr;
  530. }
  531. /**
  532. * ?? ?? ??
  533. * @access ??
  534. * @param ?? $value
  535. * @return ??
  536. */
  537. ?? ?? fieldFormat(&$value) {
  538. if(is_int($value)) {
  539. $value = intval($value);
  540. } else if(is_float($value)) {
  541. $value = floatval($value);
  542. } elseif(preg_match('/^(w* ( |-|*|/)?w*)$/i',$value)){
  543. // 支持在字段的值里face直接使用其它字段
  544. // 例如 (?? 1) (??)必須包含括號
  545. $value = $value;
  546. }else if(is_string($value)) {
  547. $value = '''.self::escape_string($value).''';
  548. }
  549. return $value;
  550. }
  551. /**
  552. *
  553. ? ?? ?? ? ??? ??? ` ??* ??? ??? ???? mysql? ?? ???? ??
  554. * @access ??
  555. * @param ?? $?
  556. * @return ??
  557. */
  558. ?? ?? addSpecialChar(&$value) {
  559. if( '*' == $value | | false !== strpos($value,'(') || false !== strpos($value,'.') || false !== strpos($value,'`')) {
  560. //如果包含* 或者 使用了sql方法 則不?處理
  561. } elseif(false === strpos($value,'`') ) {
  562. $value = '`'.trim($value).'` ';
  563. }
  564. return $value;
  565. }
  566. /**
  567. ---------------------------------- ----------
  568. * ? ?? ??
  569. ------------- ---- ------------
  570. * @access ??
  571. ---------- ----- ----------------
  572. * @param ?? $ ?
  573. ---------------------------- ----- -------------
  574. * @return ??
  575. ---------- ---- -----------------
  576. */
  577. ?? ?? RemoveEmpty($value){
  578. return !empty($value);
  579. }
  580. /**
  581. * ?? SELECT, SHOW ? ?? ??? ?? ?? ??
  582. * @access ??
  583. * @param string $sql sql ??
  584. * @return ??
  585. */
  586. ?? ?? ??($sql='') {
  587. // 獲取數(shù)據(jù)庫聯(lián)接
  588. $link = self::$link;
  589. if ( !$link ) return false;
  590. self::$queryStr = $sql;
  591. //釋放前次的查詢結果
  592. if ( !empty(self::$PDOStatement) ) self ::free();
  593. self::$PDOStatement = $link->prepare(self::$queryStr);
  594. $bol = self::$PDOStatement->execute();
  595. // 有錯誤則拋 Out異常
  596. self::haveErrorThrowException();
  597. return $bol;
  598. }
  599. /**
  600. * ?????? ?? ??
  601. * @access ??
  602. * @param string $sql ???
  603. * @param boolean $lock ?? ??(???? ?? ?? ??)
  604. * @return void
  605. ?? ?? ??($sql='',$lock=false) {
  606. if(empty($sql)) $sql = $this->queryStr
  607. return $this->_execute; ($SQL)
  608. }*/
  609. /**
  610. * INSERT, UPDATE, DELETE ???
  611. * @access ??
  612. * @param string $sql sql ??
  613. * @return ??
  614. * /
  615. ?? ?? ??($sql='') {
  616. // 獲取數(shù)據(jù)庫聯(lián)接
  617. $link = self::$link;
  618. if ( !$link ) return false;
  619. self::$queryStr = $sql;
  620. //釋放前次的查詢結果
  621. if ( !empty(self::$PDOStatement) ) self::free();
  622. $result = $link ->exec(self::$queryStr);
  623. // ?? false;
  624. } else {
  625. self::$numRows = $result;
  626. self::$lastInsertId = $link->lastInsertId();
  627. return self::$numRows;
  628. }
  629. }
  630. /**
  631. * ?????? ?? ???? ??
  632. * @access private
  633. * @param string $query SQL ??
  634. * @return boolen ?? ??? ?? false ??
  635. */
  636. ?? ?? isMainIps($query) {
  637. $queryIps = 'INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|LOAD DATA|SELECT .* INTO|COPY |ALTER|GRANT|REVOKE|LOCK|UNLOCK';
  638. if (preg_match('/^s*"?(' . $queryIps . ')s /i', $query)) {
  639. true? ?????.
  640. }
  641. false ??;
  642. }
  643. /**
  644. * POST ?? ??? ???
  645. * @access private
  646. * @param ?? $data POST ?? ???
  647. * @param string $table ??? ??? ??
  648. * @return ?? $newdata
  649. */
  650. ?? ?? filterPost($table,$data) {
  651. $table_column = self::getFields( $table);
  652. $newdata=array();
  653. foreach($table_column as $key=>$val){
  654. if(array_key_exists($key,$data) && ($data[$ ?])!==''){
  655. $newdata[$key] = $data[$key];
  656. }
  657. }
  658. return $newdata;
  659. }
  660. / **
  661. * ?? ??
  662. * @access ??
  663. * @return void
  664. */
  665. ?? ?? startTrans() {
  666. //數(shù)據(jù)rollback 支持
  667. $link = self::$link;
  668. if ( !$link ) return false;
  669. if (self::$transTimes == 0) {
  670. $link->beginTransaction();
  671. }
  672. self::$transTimes ;
  673. return ;
  674. }
  675. /**
  676. * ??? ?? ???? ?? ??? ?????.
  677. * @access ??
  678. * @return boolen
  679. */
  680. ?? ?? ??() {
  681. $link = self::$link;
  682. if ( !$link ) return false;
  683. if (self::$ transTimes > 0) {
  684. $result = $link->commit();
  685. self::$transTimes = 0;
  686. if(!$result){
  687. self::throw_Exception( self::$error());
  688. false ??;
  689. }
  690. }
  691. true ??;
  692. }
  693. /**
  694. * ???? ??
  695. * @access ??
  696. * @return bolen
  697. */
  698. ?? ?? ?? () {
  699. $link = self::$link;
  700. if ( !$link ) return false;
  701. if (self::$transTimes > 0) {
  702. $result = $link->rollback();
  703. self::$transTimes = 0;
  704. if(!$result){
  705. self::throw_Exception(self:: $error());
  706. false ??;
  707. }
  708. }
  709. true ??;
  710. }

  711. /**

  712. * ?? ??
  713. * @access ??
  714. * @return void
  715. */
  716. ?? ?? throw_Exception($err){
  717. echo '
    ??:'.$err.'
    ';
  718. }
  719. }

復代碼


本網(wǎng)站聲明
本文內容由網(wǎng)友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發(fā)現(xiàn)涉嫌抄襲或侵權的內容,請聯(lián)絡admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創(chuàng)建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發(fā)環(huán)境

Dreamweaver CS6

Dreamweaver CS6

視覺化網(wǎng)頁開發(fā)工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

如何在PHP中實施身份驗證和授權? 如何在PHP中實施身份驗證和授權? Jun 20, 2025 am 01:03 AM

tosecurelyhandleauthenticationandationallizationInphp,lofterTheSesteps:1.AlwaysHashPasswordSwithPassword_hash()andverifyusingspasspassword_verify(),usepreparedStatatementStopreventsqlineptions,andStoreSeruserDatain usseruserDatain $ _sessiveferterlogin.2.implementrole-2.imaccessccsccccccccccccccccccccccccc.

如何在PHP中安全地處理文件上傳? 如何在PHP中安全地處理文件上傳? Jun 19, 2025 am 01:05 AM

要安全處理PHP中的文件上傳,核心在於驗證文件類型、重命名文件並限制權限。 1.使用finfo_file()檢查真實MIME類型,僅允許特定類型如image/jpeg;2.用uniqid()生成隨機文件名,存儲至非Web根目錄;3.通過php.ini和HTML表單限製文件大小,設置目錄權限為0755;4.使用ClamAV掃描惡意軟件,增強安全性。這些步驟有效防止安全漏洞,確保文件上傳過程安全可靠。

PHP中==(鬆散比較)和===(嚴格的比較)之間有什麼區(qū)別? PHP中==(鬆散比較)和===(嚴格的比較)之間有什麼區(qū)別? Jun 19, 2025 am 01:07 AM

在PHP中,==與===的主要區(qū)別在於類型檢查的嚴格程度。 ==在比較前會進行類型轉換,例如5=="5"返回true,而===要求值和類型都相同才會返回true,例如5==="5"返回false。使用場景上,===更安全應優(yōu)先使用,==僅在需要類型轉換時使用。

如何與PHP的NOSQL數(shù)據(jù)庫(例如MongoDB,Redis)進行交互? 如何與PHP的NOSQL數(shù)據(jù)庫(例如MongoDB,Redis)進行交互? Jun 19, 2025 am 01:07 AM

是的,PHP可以通過特定擴展或庫與MongoDB和Redis等NoSQL數(shù)據(jù)庫交互。首先,使用MongoDBPHP驅動(通過PECL或Composer安裝)創(chuàng)建客戶端實例並操作數(shù)據(jù)庫及集合,支持插入、查詢、聚合等操作;其次,使用Predis庫或phpredis擴展連接Redis,執(zhí)行鍵值設置與獲取,推薦phpredis用於高性能場景,Predis則便於快速部署;兩者均適用於生產(chǎn)環(huán)境且文檔完善。

如何在PHP( - , *, /,%)中執(zhí)行算術操作? 如何在PHP( - , *, /,%)中執(zhí)行算術操作? Jun 19, 2025 pm 05:13 PM

PHP中使用基本數(shù)學運算的方法如下:1.加法用 號,支持整數(shù)和浮點數(shù),也可用於變量,字符串數(shù)字會自動轉換但不推薦依賴;2.減法用-號,變量同理,類型轉換同樣適用;3.乘法用*號,適用於數(shù)字及類似字符串;4.除法用/號,需避免除以零,並註意結果可能是浮點數(shù);5.取模用%號,可用於判斷奇偶數(shù),處理負數(shù)時餘數(shù)符號與被除數(shù)一致。正確使用這些運算符的關鍵在於確保數(shù)據(jù)類型清晰並處理好邊界情況。

我如何了解最新的PHP開發(fā)和最佳實踐? 我如何了解最新的PHP開發(fā)和最佳實踐? Jun 23, 2025 am 12:56 AM

TostaycurrentwithPHPdevelopmentsandbestpractices,followkeynewssourceslikePHP.netandPHPWeekly,engagewithcommunitiesonforumsandconferences,keeptoolingupdatedandgraduallyadoptnewfeatures,andreadorcontributetoopensourceprojects.First,followreliablesource

什麼是PHP,為什麼它用於Web開發(fā)? 什麼是PHP,為什麼它用於Web開發(fā)? Jun 23, 2025 am 12:55 AM

PHPbecamepopularforwebdevelopmentduetoitseaseoflearning,seamlessintegrationwithHTML,widespreadhostingsupport,andalargeecosystemincludingframeworkslikeLaravelandCMSplatformslikeWordPress.Itexcelsinhandlingformsubmissions,managingusersessions,interacti

如何設置PHP時區(qū)? 如何設置PHP時區(qū)? Jun 25, 2025 am 01:00 AM

tosetTherightTimeZoneInphp,restate_default_timezone_set()functionAtthestArtofyourscriptWithavalIdidentIdentifiersuchas'america/new_york'.1.usedate_default_default_timezone_set_set()

See all articles