PageRenderTime 26ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/ php-ppcms/includes/classes/database.mysql.link.class.php

http://php-ppcms.googlecode.com/
PHP | 887 lines | 671 code | 153 blank | 63 comment | 97 complexity | 8f8848be24aa5c49ad4f5fd6ff3fd83d MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. <?php
  2. /***************************************************************
  3. * Copyright notice
  4. * (c) 2009, jianyuzhu@gmail.com
  5. * All rights reserved
  6. * This script is part of the PPEMI project.
  7. ***************************************************************/
  8. class ADODBDatabase {
  9. var $database = '';
  10. var $dbType = 'mysql';
  11. var $dbHostName = '';
  12. var $dbUserName = '';
  13. var $dbPassword = '';
  14. var $dbName = '';
  15. var $lastmysqlrow = -1;
  16. //
  17. var $enableSQLlog = false;
  18. var $dieOnError = false;
  19. //query time
  20. var $queryTime = 0;
  21. //query count from the page start to the end
  22. //internal counter
  23. var $queryCount = 0;
  24. //
  25. var $_link = '_db_link';
  26. //constructor
  27. function &getInstance() {
  28. static $instance;
  29. if( !is_object($instance) ) {
  30. $instance = & new ADODBDatabase();
  31. }
  32. return $instance;
  33. }
  34. function isMySQL() {
  35. return ($this->dbType == 'mysql');
  36. }
  37. function setDbType($dbType) {
  38. $this->dbType = $dbType;
  39. }
  40. function getDbType() {
  41. return $this->dbType;
  42. }
  43. function setDbHostName($dbHostName) {
  44. $this->dbHostName = $dbHostName;
  45. }
  46. function getDbHostName() {
  47. return $this->dbHostName;
  48. }
  49. function setDbUserName($dbUserName) {
  50. $this->dbUserName = $dbUserName;
  51. }
  52. function getDbUserName() {
  53. return $this->dbUserName;
  54. }
  55. function setDbPassword($dbPassword) {
  56. $this->dbPassword = $dbPassword;
  57. }
  58. function getDbPassword() {
  59. return $this->dbPassword;
  60. }
  61. function setDbName($dbName) {
  62. $this->dbName = $dbName;
  63. }
  64. function getDbName() {
  65. return $this->dbName;
  66. }
  67. function change_key_case($arr) {
  68. return is_array($arr)?array_change_key_case($arr):$arr;
  69. }
  70. //construction
  71. function ADODBDatabase($dbtype = '', $hostname = '', $dbname = '', $username = '', $password = '') {
  72. $this->initSettings();
  73. $this->resetSettings($dbtype, $hostname, $dbname, $username, $password);
  74. }
  75. function initSettings() {
  76. $this->db_type = CONFIG_DB_TYPE;
  77. $this->db_host = CONFIG_DB_HOST;
  78. $this->db_user = CONFIG_DB_USER;
  79. $this->db_password = CONFIG_DB_PASSWORD;
  80. $this->db_name = CONFIG_DB_NAME;
  81. $this->db_prefix = CONFIG_DB_PREFIX;
  82. $this->db_pconnect = CONFIG_DB_PCONNECT;
  83. $this->db_logsql = CONFIG_DB_LOGSQL;
  84. $this->db_logfile = CONFIG_DB_LOGFILE;
  85. }
  86. function resetSettings($dbtype = '', $hostname = '', $dbname = '', $username = '', $password = '') {
  87. if( $hostname == '' ) {
  88. $this->disconnect();
  89. $this->setDbType($this->db_type);
  90. $this->setDbHostName($this->db_host);
  91. $this->setDbUserName($this->db_user);
  92. $this->setDbPassword($this->db_password);
  93. $this->setDbName($this->db_name);
  94. if( $this->db_logsql ) {
  95. $this->enableSQLlog = ($this->db_logsql == true);
  96. }
  97. } else {
  98. $this->disconnect();
  99. $this->setDbType($dbtype);
  100. $this->setDbHostName($hostname);
  101. $this->setDbUserName($username);
  102. $this->setDbPassword($password);
  103. $this->setDbName($dbname);
  104. }
  105. }
  106. function connect($link = '_db_link') {
  107. if( !isset($this->dbType) ) {
  108. return false;
  109. }
  110. global $$link;
  111. if( $this->db_pconnect == 'true' ) {
  112. $$link = mysql_pconnect($this->dbHostName, $this->dbUserName, $this->dbPassword) or die('DBECP');
  113. } else {
  114. $$link = mysql_connect($this->dbHostName, $this->dbUserName, $this->dbPassword) or die('DBEC');
  115. }
  116. if( $$link ) {
  117. mysql_select_db($this->dbName) or die('DBEDB');
  118. $this->database = $$link;
  119. }
  120. return $$link;
  121. }
  122. function checkConnection() {
  123. if( !isset($this->database) ) {
  124. $this->connect();
  125. } else {
  126. }
  127. }
  128. function disconnect($link = '_db_link') {
  129. //global $$link;
  130. //return mysql_close($$link);
  131. }
  132. function close($link = '_db_link') {
  133. global $$link;
  134. return mysql_close($$link);
  135. }
  136. function error($sql, $errno, $error) {
  137. die($errno . '<br>' . $error . '<br>' . $sql);
  138. }
  139. //QUERY
  140. function query($sql, $link = '_db_link') {
  141. global $$link;
  142. $this->checkConnection();
  143. //if( $this->enableSQLlog == 'true') ) {
  144. // error_log('QUERY ' . $query . "\n", 3, $this->db_logfile);
  145. //}
  146. //$result = mysql_query($sql, $$link) or $this->error($sql, mysql_errno(), mysql_error());
  147. $result = mysql_query($sql, $$link);
  148. if( !$result ) {
  149. //return false;
  150. $this->error($sql, mysql_errno(), mysql_error());
  151. }
  152. //if( $this->enableSQLlog == 'true') ) {
  153. // error_log('RESULT ' . $result . ' ' . mysql_errno() . ' ' . mysql_error() . "\n", 3, $this->db_logfile);
  154. //}
  155. //counter
  156. $this->addQueryCount();
  157. //log
  158. $this->addQueryLog($sql);
  159. return $result;
  160. }
  161. function perform($table, $data, $action = 'insert', $parameters = '', $link = '_db_link') {
  162. reset($data);
  163. if( $action == 'insert' || $action == 'replace' ) {
  164. //$sql = 'insert into ' . $table . ' (';
  165. $sql = $action . ' into ' . $table . ' (';
  166. while( list($columns, ) = each($data) ) {
  167. $sql .= $columns . ', ';
  168. }
  169. $sql = substr($sql, 0, -2) . ') values (';
  170. reset($data);
  171. while( list($columns, $value) = each($data) ) {
  172. switch( (string)$value ) {
  173. case 'now()':
  174. $sql .= 'now(), ';
  175. break;
  176. case 'add_one()':
  177. $sql .= $columns . ' + 1, ';
  178. break;
  179. case 'null':
  180. $sql .= 'null, ';
  181. break;
  182. default:
  183. $sql .= '\'' . $this->str_input($value) . '\', ';
  184. break;
  185. }
  186. }
  187. $sql = substr($sql, 0, -2) . ')';
  188. } elseif( $action == 'update' ) {
  189. $sql = 'update ' . $table . ' set ';
  190. while( list($columns, $value) = each($data) ) {
  191. switch( (string)$value ) {
  192. case 'now()':
  193. $sql .= $columns . ' = now(), ';
  194. break;
  195. case 'add_one()':
  196. $sql .= $columns . ' = ' . $columns . ' + 1, ';
  197. break;
  198. case 'null':
  199. $sql .= $columns .= ' = null, ';
  200. break;
  201. default:
  202. $sql .= $columns . ' = \'' . $this->str_input($value) . '\', ';
  203. break;
  204. }
  205. }
  206. $sql = substr($sql, 0, -2) . ' where ' . $parameters;
  207. }
  208. return $this->query($sql, $link);
  209. }
  210. function add($sql) {
  211. $result = $this->query($sql);
  212. if( !$result ) {
  213. return false;
  214. }
  215. return true;
  216. }
  217. function insert($sql) {
  218. $result = $this->query($sql);
  219. if( !$result ) {
  220. return false;
  221. }
  222. $insert_id = $this->insert_id();
  223. return $insert_id;
  224. }
  225. function update($sql) {
  226. $result = $this->query($sql);
  227. if( !$result ) {
  228. return false;
  229. }
  230. return true;
  231. }
  232. function delete($sql) {
  233. $result = $this->query($sql);
  234. if( !$result ) {
  235. return false;
  236. }
  237. return true;
  238. }
  239. function updateField($table, $id, $field, $value, $pk = '') {
  240. if( $pk == '' ) {
  241. $pk = $table . '_id';
  242. }
  243. $sql = "update " . $table . " set " . $field . " = '" . func_db_input($value) . "' where " . $pk . " = '" . $id . "' limit 1";
  244. return $this->update($sql);
  245. }
  246. function updateFieldC($table, $id, $field, $value, $pk = '') {
  247. if( $pk == '' ) {
  248. $pk = $table . '_id';
  249. }
  250. $count = $this->getCountA($table, " " . $pk . " != '" . $id . "' and " . $field . " = '" . func_db_input($value) . "' ");
  251. if( $count > 0 ) {
  252. return -1;
  253. } else {
  254. return $this->updateField($table, $id, $field, $value, $pk);
  255. }
  256. }
  257. function updateRow($table, $id, $field, $value, $pk = '') {
  258. if( $pk == '' ) {
  259. $pk = $table . '_id';
  260. }
  261. $sql = "update " . $table . " set " . $field . " = '" . func_db_input($value) . "' where " . $pk . " = '" . $id . "' limit 1";
  262. return $this->update($sql);
  263. }
  264. function updateRowC($table, $id, $field, $value, $pk = '') {
  265. if( $pk == '' ) {
  266. $pk = $table . '_id';
  267. }
  268. $count = $this->getCountA($table, " " . $pk . " != '" . $id . "' and " . $field . " = '" . func_db_input($value) . "' ");
  269. if( $count > 0 ) {
  270. return -1;
  271. } else {
  272. return $this->updateRow($table, $id, $field, $value, $pk);
  273. }
  274. }
  275. function deleteRow($table, $id, $pk = '') {
  276. if( $pk == '' ) {
  277. $pk = $table . '_id';
  278. }
  279. $sql = "delete from " . $table . " where " . $pk . " = '" . (int)$id . "' limit 1";
  280. return $this->delete($sql);
  281. }
  282. function addA($table, $data) {
  283. $result = $this->perform($table, $data);
  284. if( !$result ) {
  285. return false;
  286. }
  287. return true;
  288. }
  289. function insertA($table, $data) {
  290. $result = $this->perform($table, $data);
  291. if( !$result ) {
  292. return false;
  293. }
  294. $insert_id = $this->insert_id();
  295. return $insert_id;
  296. }
  297. function updateA($table, $data, $parameters) {
  298. $result = $this->perform($table, $data, 'update', $parameters);
  299. if( !$result ) {
  300. return false;
  301. }
  302. return true;
  303. }
  304. function deleteA($table, $parameters) {
  305. $sql = "delete from " . $table . " where " . $parameters;
  306. return $this->delete($sql);
  307. }
  308. //RESULT
  309. function fetch_array($db_query) {
  310. return mysql_fetch_array($db_query, MYSQL_ASSOC);
  311. }
  312. function fetch_array_assoc($db_query) {
  313. return mysql_fetch_array($db_query, MYSQL_ASSOC);
  314. }
  315. function fetch_array_num($db_query) {
  316. return mysql_fetch_array($db_query, MYSQL_NUM);
  317. }
  318. function fetch_array_both($db_query) {
  319. return mysql_fetch_array($db_query, MYSQL_BOTH);
  320. }
  321. function fetch_assoc($db_query) {
  322. return mysql_fetch_assoc($db_query);
  323. }
  324. function fetch_object($db_query) {
  325. return mysql_fetch_object($db_query);
  326. }
  327. function fetch_objects($db_query) {
  328. $objects = array();
  329. while($row = mysql_fetch_object($db_query)) {
  330. $objects[] = $row;
  331. }
  332. return $objects;
  333. }
  334. function num_rows($db_query) {
  335. return mysql_num_rows($db_query);
  336. }
  337. function affected_rows($link = '_db_link') {
  338. global $$link;
  339. return mysql_affected_rows($$link);
  340. }
  341. function data_seek($db_query, $row_number) {
  342. return mysql_data_seek($db_query, $row_number);
  343. }
  344. function getUniqueID($table) {
  345. $id = $table . "_id";
  346. $query = "select MAX(" . $id . ") as last_id from " . $table . "";
  347. //$result = mysql_query($query);
  348. //$row = mysql_fetch_array($result);
  349. $result = $this->query($query);
  350. $row = $this->fetch_array($result);
  351. $next_id = $row['last_id'] + 1;
  352. return $next_id;
  353. }
  354. function insert_id() {
  355. return mysql_insert_id();
  356. }
  357. function free_result($db_query) {
  358. return mysql_free_result($db_query);
  359. }
  360. function fetch_fields($db_query) {
  361. $fields_array = array();
  362. $i = 0;
  363. while($i < mysql_num_fields($db_query)) {
  364. $meta = mysql_fetch_field($db_query, $i);
  365. if( !$meta ) {
  366. $this->error("fetch_fields", "mysql_fetch_field", "");
  367. }
  368. $fields_array[] = array(
  369. 'blob' => $meta->blob,
  370. 'max_length' => $meta->max_length,
  371. 'multiple_key' => $meta->multiple_key,
  372. 'name' => $meta->name,
  373. 'not_null' => $meta->not_null,
  374. 'numeric' => $meta->numeric,
  375. 'primary_key' => $meta->primary_key,
  376. 'table' => $meta->table,
  377. 'type' => $meta->type,
  378. 'unique_key' => $meta->unique_key,
  379. 'unsigned' => $meta->unsigned,
  380. 'zerofill' => $meta->zerofill,
  381. );
  382. $i++;
  383. }
  384. return $fields_array;
  385. }
  386. //
  387. function getOne($sql) {
  388. $result = $this->query($sql);
  389. $row = $this->fetch_array($result);
  390. return $row;
  391. }
  392. function getRow($sql, $field = '') {
  393. $result = $this->query($sql);
  394. $row = $this->fetch_array($result);
  395. if( $field == '' ) {
  396. return $row;
  397. } elseif( is_array($field) ) {
  398. $rowb = array();
  399. foreach($field as $k => $v) {
  400. if( isset($row[$v]) ) {
  401. $rowb[] = $row[$v];
  402. }
  403. }
  404. return $rowb;
  405. } else {
  406. return $row[$field];
  407. }
  408. }
  409. function getRows($sql, $limit = false) {
  410. $i = 0;
  411. $result = $this->query($sql);
  412. while($row = $this->fetch_array($result)) {
  413. $rows[] = $row;
  414. if( $limit > 0 && $i > $limit ) {
  415. break;
  416. }
  417. $i++;
  418. }
  419. return $rows;
  420. }
  421. function getRowLight($table, $key, $value) {
  422. $sql = "select * from " . $table . " where " . $key . " = '" . $value . "'";
  423. return $this->getRow($sql);
  424. }
  425. function getRowParam($table, $param) {
  426. $query = "select * from " . $table . " ";
  427. if( is_array($param) ) {
  428. foreach($param as $k => $v) {
  429. if( $i == 0 ) {
  430. $query .= " where ";
  431. $query .= " " . $k . " = '" . $v . "' ";
  432. } else {
  433. $query .= " and ";
  434. $query .= " " . $k . " = '" . $v . "' ";
  435. }
  436. }
  437. }
  438. return $this->getRow($sql);
  439. }
  440. function getCount($sql) {
  441. $result = $this->query($sql);
  442. $row = $this->fetch_array($result);
  443. if( is_array($row) ) {
  444. if( isset($row['count']) ) {
  445. return $row['count'];
  446. } elseif( strpos($sql, 'count(') !== false ) {
  447. return $row['0'];
  448. } else {
  449. return $this->num_rows($result);
  450. }
  451. }
  452. return 0;
  453. }
  454. function getField($sql, $field) {
  455. $row = $this->getRow($sql);
  456. if( is_array($row) && isset($row[$field]) ) {
  457. return $row[$field];
  458. }
  459. return '';
  460. }
  461. function checkCount($sql, $unique = false) {
  462. $count = $this->getCount($sql);
  463. if( $unique == true ) {
  464. return ($count == 1) ? true : false;
  465. } else {
  466. return ($count > 0) ? true : false;
  467. }
  468. }
  469. //
  470. function getOneA($table, $parameters = '') {
  471. if( $parameters == '' ) {
  472. $parameters = '1';
  473. }
  474. $sql = "select * from " . $table . " where " . $parameters;
  475. return $this->getRow($sql);
  476. }
  477. function getRowA($table, $parameters = '') {
  478. if( $parameters == '' ) {
  479. $parameters = '1';
  480. }
  481. $sql = "select * from " . $table . " where " . $parameters;
  482. return $this->getRow($sql);
  483. }
  484. function getRowsA($table, $parameters = '', $limit = false) {
  485. if( $parameters == '' ) {
  486. $parameters = '1';
  487. }
  488. $sql = "select * from " . $table . " where " . $parameters;
  489. return $this->getRows($sql, $limit);
  490. }
  491. function getCountA($table, $parameters = '') {
  492. if( $parameters == '' ) {
  493. $parameters = '1';
  494. }
  495. $sql = "select count(*) as count from " . $table . " where " . $parameters;
  496. return $this->getCount($sql);
  497. }
  498. function checkCountA($table, $parameters, $unique = false) {
  499. $count = $this->getCountA($table, $parameters);
  500. if( $unique == true ) {
  501. return ($count == 1) ? true : false;
  502. } else {
  503. return ($count > 0) ? true : false;
  504. }
  505. }
  506. //STRING
  507. function str_output($string) {
  508. return htmlspecialchars($string);
  509. }
  510. function str_input($string) {
  511. return addslashes($string);
  512. }
  513. function str_prepare_input($string) {
  514. if( is_string($string)) {
  515. return trim(util_string_sanitize(stripslashes($string)));
  516. } elseif( is_array($string)) {
  517. reset($string);
  518. while( list($key, $value) = each($string) ) {
  519. $string[$key] = $this->str_input($value);
  520. }
  521. return $string;
  522. } else {
  523. return $string;
  524. }
  525. }
  526. function escape_string($string) {
  527. return mysql_escape_string($string);
  528. }
  529. //META
  530. function info($link = '_db_link') {
  531. global $$link;
  532. return mysql_info($$link);
  533. }
  534. function getDbs($link = '_db_link') {
  535. global $$link;
  536. $result = mysql_list_dbs($$link);
  537. if( !$result ) {
  538. $this->error("mysql_list_dbs", "mysql_list_dbs", "");
  539. }
  540. $dbs = array();
  541. while($row = mysql_fetch_object($result)) {
  542. $dbs[] = $row->Database;
  543. }
  544. /*
  545. //
  546. $i = 0;
  547. $num_rows = mysql_num_rows($result);
  548. while($i < $num_rows) {
  549. $dbs[] = mysql_db_name($result, $i);
  550. $i++;
  551. }
  552. */
  553. return $dbs;
  554. }
  555. function getTables($link = '_db_link') {
  556. global $$link;
  557. $result = mysql_list_tables($this->dbName, $$link);
  558. if( !$result ) {
  559. $this->error("mysql_list_tables", "mysql_list_tables", "");
  560. }
  561. $tables = array();
  562. /*
  563. while($row = mysql_fetch_row($result)) {
  564. $tables[] = $row['0'];
  565. }
  566. */
  567. $num_rows = mysql_num_rows($result);
  568. for($i=0; $i<$num_rows; $i++) {
  569. $tables[] = mysql_tablename($result, $i);
  570. }
  571. mysql_free_result($result);
  572. return $tables;
  573. }
  574. function getMetadata($table, $link = '_db_link') {
  575. global $$link;
  576. $count = 0;
  577. $id = 0;
  578. $metadata_array = array();
  579. $result = mysql_list_fields($this->dbName, $table, $$link);
  580. if( $result < 0 ) {
  581. $this->error("mysql_list_fields", "mysql_list_fields", "");
  582. }
  583. $count = mysql_num_fields($result);
  584. for($i=0; $i<$count; $i++) {
  585. $field_table = mysql_field_table($result, $i);
  586. $field_name = mysql_field_name($result, $i);
  587. $field_type = mysql_field_type($result, $i);
  588. $field_len = mysql_field_len($result, $i);
  589. $field_flags = mysql_field_flags($result, $i);
  590. $metadata_array[] = array(
  591. 'table' => $field_table,
  592. 'name' => $field_name,
  593. 'type' => $field_type,
  594. 'len' => $field_len,
  595. 'flags' => $field_flags,
  596. //'meta' => $i,
  597. );
  598. }
  599. mysql_free_result($result);
  600. return $metadata_array;
  601. }
  602. function getFields($table, $link = '_db_link') {
  603. global $$link;
  604. $sql = "select * from " . $table . " where 1 limit 1";
  605. $result = mysql_query($sql, $$link);
  606. if( !$result ) {
  607. $this->error("getFields", "getFields", "");
  608. }
  609. $fields_array = array();
  610. $i = 0;
  611. while($i < mysql_num_fields($result)) {
  612. $meta = mysql_fetch_field($result, $i);
  613. if( !$meta ) {
  614. $this->error("getFields", "mysql_fetch_field", "");
  615. }
  616. $fields_array[] = array(
  617. 'blob' => $meta->blob,
  618. 'max_length' => $meta->max_length,
  619. 'multiple_key' => $meta->multiple_key,
  620. 'name' => $meta->name,
  621. 'not_null' => $meta->not_null,
  622. 'numeric' => $meta->numeric,
  623. 'primary_key' => $meta->primary_key,
  624. 'table' => $meta->table,
  625. 'type' => $meta->type,
  626. 'unique_key' => $meta->unique_key,
  627. 'unsigned' => $meta->unsigned,
  628. 'zerofill' => $meta->zerofill,
  629. );
  630. $i++;
  631. }
  632. return $fields_array;
  633. }
  634. function getFieldsA($table) {
  635. $fields_a = array();
  636. $fields = $this->getFields($table);
  637. if( is_array($fields) ) {
  638. for($i=0, $n=sizeof($fields); $i<$n; $i++) {
  639. $fields_a[] = $fields[$i]['name'];
  640. }
  641. }
  642. return $fields_a;
  643. }
  644. //DB
  645. function createDatabase($db_name, $link = '_db_link') {
  646. /*
  647. //
  648. global $$link;
  649. $result = mysql_create_db($db_name, $$link);
  650. if( $result ) {
  651. return true;
  652. }
  653. */
  654. $sql = "CREATE DATABASE '" . $db_name . "'";
  655. $result = $this->query($sql, $link);
  656. if( $result ) {
  657. return true;
  658. }
  659. return false;
  660. }
  661. function createTable($table_name, $sql, $link = '_db_link') {
  662. $tables = $this->getTables($link);
  663. if( in_array($db_name, $tables) ) {
  664. return false;
  665. }
  666. $charset = '';
  667. $sql = $this->createTableSQL($sql, $charset);
  668. return $this->query($sql);
  669. }
  670. function createTableSQL($sql, $charset = '') {
  671. $type = strtoupper(preg_replace("/^\s*CREATE TABLE\s+.+\s+\(.+?\).*(ENGINE|TYPE)\s*=\s*([a-z]+?).*$/isU", "\\2", $sql));
  672. $type = in_array($type, array('MYISAM', 'HEAP')) ? $type : 'MYISAM';
  673. $sql = preg_replace("/^\s*(CREATE TABLE\s+.+\s+\(.+?\)).*$/isU", "\\1", $sql) . (mysql_get_server_info() > '4.1' ? " ENGINE=$type DEFAULT CHARSET=$dbcharset" : " TYPE=$type");
  674. return $sql;
  675. }
  676. function getIncrementID($table) {
  677. $row = $this->getRow("SHOW TABLE STATUS LIKE '" . $table . "'");
  678. if( $row['Auto_increment'] ) {
  679. return $row['Auto_increment'] - 1;
  680. }
  681. return 0;
  682. }
  683. function getMaxID() {
  684. $row = $this->getRow("SHOW TABLE STATUS LIKE '" . $table . "'");
  685. if( $row['Auto_increment'] ) {
  686. return $row['Auto_increment'] - 1;
  687. }
  688. return 0;
  689. }
  690. //query Count Operation
  691. function addQueryCount() {
  692. global $system_db_query_count;
  693. if( !isset($system_db_query_count) ) {
  694. $system_db_query_count = 0;
  695. }
  696. $system_db_query_count++;
  697. $this->queryCount++;
  698. }
  699. function getQueryCount() {
  700. global $system_db_query_count;
  701. if( isset($system_db_query_count) ) {
  702. return $system_db_query_count;
  703. }
  704. return $this->queryCount;
  705. }
  706. //
  707. function addQueryLog($sql) {
  708. global $system_db_query_logs;
  709. if( isset($system_db_query_logs) && $system_db_query_logs == -1 ) {
  710. return false;
  711. }
  712. global $system_db_query_log;
  713. if( !isset($system_db_query_log) ) {
  714. $system_db_query_log = array();
  715. }
  716. $system_db_query_log[] = $sql;
  717. }
  718. function getQueryLog() {
  719. global $system_db_query_log;
  720. if( isset($system_db_query_log) ) {
  721. return $system_db_query_log;
  722. }
  723. return $this->queryLog;
  724. }
  725. //
  726. function getCachedRow($sql) {
  727. }
  728. //
  729. function _get_hash_key($key) {
  730. return abs(crc32($key)) . '_' . md5($key);
  731. }
  732. }
  733. //
  734. ?>