/Quản lý website trường trung học phổ thông PHP/lc1/includes/class/mysql.class.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien · PHP · 735 lines · 493 code · 82 blank · 160 comment · 81 complexity · 14502fd52542403be97c54e5a4ddd4e2 MD5 · raw file

  1. <?php
  2. /**
  3. * @Project NUKEVIET 3.0
  4. * @Author VINADES.,JSC (contact@vinades.vn)
  5. * @Copyright (C) 2010 VINADES., JSC. All rights reserved
  6. * @Createdate 3/28/2010 19:3
  7. */
  8. if ( defined( 'NV_CLASS_SQL_DB_PHP' ) ) return;
  9. define( 'NV_CLASS_SQL_DB_PHP', true );
  10. if ( ! defined( 'NV_SITE_TIMEZONE_NAME' ) ) define( 'NV_SITE_TIMEZONE_NAME', '+00:00' );
  11. /**
  12. * sql_db
  13. *
  14. * @package
  15. * @author NUKEVIET 3.0
  16. * @copyright VINADES
  17. * @version 2010
  18. * @access public
  19. */
  20. class sql_db
  21. {
  22. const NOT_CONNECT_TO_MYSQL_SERVER = 'Sorry! Could not connect to mysql server';
  23. const DATABASE_NAME_IS_EMPTY = 'Error! The database name is not the connection name';
  24. const UNKNOWN_DATABASE = 'Error! Unknown database';
  25. public $server = 'localhost';
  26. public $user = 'root';
  27. public $dbname = '';
  28. public $sql_version;
  29. public $db_charset;
  30. public $db_collation;
  31. public $db_time_zone;
  32. public $error = array();
  33. public $time = 0;
  34. public $query_strs = array();
  35. private $persistency = false;
  36. private $new_link = false;
  37. private $db_connect_id = false;
  38. private $create_db = false;
  39. private $query_result = false;
  40. private $row = array();
  41. private $rowset = array();
  42. /**
  43. * sql_db::__construct()
  44. *
  45. * @param mixed $db_config
  46. * @return
  47. */
  48. public function __construct ( $db_config = array() )
  49. {
  50. $stime = array_sum( explode( " ", microtime() ) );
  51. if ( isset( $db_config['dbhost'] ) and ! empty( $db_config['dbhost'] ) ) $this->server = $db_config['dbhost'];
  52. if ( isset( $db_config['dbport'] ) and ! empty( $db_config['dbport'] ) ) $this->server .= ':' . $db_config['dbport'];
  53. if ( isset( $db_config['dbname'] ) ) $this->dbname = $db_config['dbname'];
  54. if ( isset( $db_config['dbuname'] ) ) $this->user = $db_config['dbuname'];
  55. if ( isset( $db_config['new_link'] ) ) $this->new_link = ( bool )$db_config['new_link'];
  56. if ( isset( $db_config['create_db'] ) ) $this->create_db = ( bool )$db_config['create_db'];
  57. if ( isset( $db_config['persistency'] ) ) $this->persistency = ( bool )$db_config['persistency'];
  58. $this->sql_connect( $db_config['dbpass'] );
  59. if ( $this->db_connect_id ) $this->sql_setdb();
  60. $this->time += ( array_sum( explode( " ", microtime() ) ) - $stime );
  61. }
  62. /**
  63. * sql_db::sql_connect()
  64. *
  65. * @return
  66. */
  67. private function sql_connect ( $dbpass )
  68. {
  69. $function = ( $this->persistency ) ? 'mysql_pconnect' : 'mysql_connect';
  70. $this->db_connect_id = @call_user_func( $function, $this->server, $this->user, $dbpass, $this->new_link );
  71. unset( $dbpass );
  72. if ( ! $this->db_connect_id )
  73. {
  74. $this->error = $this->sql_error( sql_db::NOT_CONNECT_TO_MYSQL_SERVER );
  75. }
  76. else
  77. {
  78. if ( empty( $this->dbname ) )
  79. {
  80. $this->error = $this->sql_error( sql_db::DATABASE_NAME_IS_EMPTY );
  81. $this->db_connect_id = false;
  82. }
  83. else
  84. {
  85. $dbselect = @mysql_select_db( $this->dbname, $this->db_connect_id );
  86. if ( ! $dbselect )
  87. {
  88. if ( $this->create_db )
  89. {
  90. @mysql_query( "CREATE DATABASE " . $this->dbname . "", $this->db_connect_id );
  91. $dbselect = @mysql_select_db( $this->dbname, $this->db_connect_id );
  92. }
  93. if ( ! $dbselect )
  94. {
  95. $this->error = $this->sql_error( sql_db::UNKNOWN_DATABASE );
  96. @mysql_close( $this->db_connect_id );
  97. $this->db_connect_id = false;
  98. }
  99. }
  100. }
  101. }
  102. }
  103. /**
  104. * sql_db::sql_setdb()
  105. *
  106. * @return
  107. */
  108. private function sql_setdb ( )
  109. {
  110. if ( $this->db_connect_id )
  111. {
  112. preg_match( "/^(\d+)\.(\d+)\.(\d+)/", mysql_get_server_info(), $m );
  113. $this->sql_version = ( $m[1] . '.' . $m[2] . '.' . $m[3] );
  114. if ( version_compare( $this->sql_version, '4.1.0', '>=' ) )
  115. {
  116. @mysql_query( "SET SESSION `time_zone`='" . NV_SITE_TIMEZONE_NAME . "'", $this->db_connect_id );
  117. $result = @mysql_query( 'SELECT @@session.time_zone AS `time_zone`, @@session.character_set_database AS `character_set_database`,
  118. @@session.collation_database AS `collation_database`, @@session.sql_mode AS `sql_mode`', $this->db_connect_id );
  119. $row = @mysql_fetch_assoc( $result );
  120. @mysql_free_result( $result );
  121. $this->db_time_zone = $row['time_zone'];
  122. $this->db_charset = $row['character_set_database'];
  123. $this->db_collation = $row['collation_database'];
  124. if ( strcasecmp( $this->db_charset, "utf8" ) != 0 or strcasecmp( $this->db_collation, "utf8_general_ci" ) != 0 )
  125. {
  126. @mysql_query( "ALTER DATABASE `" . $this->dbname . "` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_general_ci`", $this->db_connect_id );
  127. $result = @mysql_query( 'SELECT @@session.character_set_database AS `character_set_database`,
  128. @@session.collation_database AS `collation_database`', $this->db_connect_id );
  129. $row = @mysql_fetch_assoc( $result );
  130. @mysql_free_result( $result );
  131. $this->db_charset = $row['character_set_database'];
  132. $this->db_collation = $row['collation_database'];
  133. }
  134. @mysql_query( "SET NAMES 'utf8'", $this->db_connect_id );
  135. if ( version_compare( $this->sql_version, '5.0.2', '>=' ) )
  136. {
  137. $modes = ( ! empty( $row['sql_mode'] ) ) ? array_map( 'trim', explode( ',', $row['sql_mode'] ) ) : array();
  138. if ( ! in_array( 'TRADITIONAL', $modes ) )
  139. {
  140. if ( ! in_array( 'STRICT_ALL_TABLES', $modes ) ) $modes[] = 'STRICT_ALL_TABLES';
  141. if ( ! in_array( 'STRICT_TRANS_TABLES', $modes ) ) $modes[] = 'STRICT_TRANS_TABLES';
  142. }
  143. $mode = implode( ',', $modes );
  144. @mysql_query( "SET SESSION `sql_mode`='" . $mode . "'", $this->db_connect_id );
  145. }
  146. }
  147. }
  148. }
  149. /**
  150. * sql_db::sql_close()
  151. *
  152. * @return
  153. */
  154. public function sql_close ( )
  155. {
  156. if ( $this->db_connect_id )
  157. {
  158. if ( is_resource( $this->query_result ) ) @mysql_free_result( $this->query_result );
  159. if ( ! $this->persistency )
  160. {
  161. $result = @mysql_close( $this->db_connect_id );
  162. if ( ! $result ) $this->error = $this->sql_error();
  163. $this->db_connect_id = null;
  164. $this->row = array();
  165. $this->rowset = array();
  166. return $result;
  167. }
  168. }
  169. return false;
  170. }
  171. /**
  172. * sql_db::sql_query()
  173. *
  174. * @param string $query
  175. * @return
  176. */
  177. public function sql_query ( $query = "" )
  178. {
  179. $stime = array_sum( explode( " ", microtime() ) );
  180. $this->query_result = false;
  181. if ( ! empty( $query ) )
  182. {
  183. $query = preg_replace( '/union/', 'UNI0N', $query );
  184. $this->query_result = @mysql_query( $query, $this->db_connect_id );
  185. $this->query_strs[] = array(
  186. htmlspecialchars( $query ), ( $this->query_result ? true : false )
  187. );
  188. }
  189. if ( $this->query_result )
  190. {
  191. unset( $this->row[$this->query_result] );
  192. unset( $this->rowset[$this->query_result] );
  193. $this->time += ( array_sum( explode( " ", microtime() ) ) - $stime );
  194. return $this->query_result;
  195. }
  196. else
  197. {
  198. $this->time += ( array_sum( explode( " ", microtime() ) ) - $stime );
  199. return false;
  200. }
  201. }
  202. /**
  203. * sql_db::sql_query_insert_id()
  204. *
  205. * @param string $query
  206. * @return
  207. */
  208. public function sql_query_insert_id ( $query = "" )
  209. {
  210. if ( empty( $query ) or ! preg_match( "/^INSERT\s/is", $query ) )
  211. {
  212. return false;
  213. }
  214. if ( ! $this->sql_query( $query ) )
  215. {
  216. return false;
  217. }
  218. $result = @mysql_insert_id( $this->db_connect_id );
  219. return $result;
  220. }
  221. /**
  222. * sql_db::sql_numrows()
  223. *
  224. * @param integer $query_id
  225. * @return
  226. */
  227. public function sql_numrows ( $query_id = 0 )
  228. {
  229. $stime = array_sum( explode( " ", microtime() ) );
  230. if ( empty( $query_id ) ) $query_id = $this->query_result;
  231. if ( ! empty( $query_id ) )
  232. {
  233. $result = @mysql_num_rows( $query_id );
  234. $this->time += ( array_sum( explode( " ", microtime() ) ) - $stime );
  235. return $result;
  236. }
  237. $this->time += ( array_sum( explode( " ", microtime() ) ) - $stime );
  238. return false;
  239. }
  240. /**
  241. * sql_db::sql_affectedrows()
  242. *
  243. * @return
  244. */
  245. public function sql_affectedrows ( )
  246. {
  247. $stime = array_sum( explode( " ", microtime() ) );
  248. if ( $this->db_connect_id )
  249. {
  250. $result = @mysql_affected_rows( $this->db_connect_id );
  251. $this->time += ( array_sum( explode( " ", microtime() ) ) - $stime );
  252. return $result;
  253. }
  254. $this->time += ( array_sum( explode( " ", microtime() ) ) - $stime );
  255. return false;
  256. }
  257. /**
  258. * sql_db::sql_numfields()
  259. *
  260. * @param integer $query_id
  261. * @return
  262. */
  263. public function sql_numfields ( $query_id = 0 )
  264. {
  265. $stime = array_sum( explode( " ", microtime() ) );
  266. if ( empty( $query_id ) ) $query_id = $this->query_result;
  267. if ( ! empty( $query_id ) )
  268. {
  269. $result = @mysql_num_fields( $query_id );
  270. $this->time += ( array_sum( explode( " ", microtime() ) ) - $stime );
  271. return $result;
  272. }
  273. $this->time += ( array_sum( explode( " ", microtime() ) ) - $stime );
  274. return false;
  275. }
  276. /**
  277. * sql_db::sql_fieldname()
  278. *
  279. * @param mixed $offset
  280. * @param integer $query_id
  281. * @return
  282. */
  283. public function sql_fieldname ( $offset, $query_id = 0 )
  284. {
  285. $stime = array_sum( explode( " ", microtime() ) );
  286. if ( empty( $query_id ) ) $query_id = $this->query_result;
  287. if ( ! empty( $query_id ) )
  288. {
  289. $result = @mysql_field_name( $query_id, $offset );
  290. $this->time += ( array_sum( explode( " ", microtime() ) ) - $stime );
  291. return $result;
  292. }
  293. $this->time += ( array_sum( explode( " ", microtime() ) ) - $stime );
  294. return false;
  295. }
  296. /**
  297. * sql_db::sql_fieldtype()
  298. *
  299. * @param mixed $offset
  300. * @param integer $query_id
  301. * @return
  302. */
  303. public function sql_fieldtype ( $offset, $query_id = 0 )
  304. {
  305. $stime = array_sum( explode( " ", microtime() ) );
  306. if ( empty( $query_id ) ) $query_id = $this->query_result;
  307. if ( ! empty( $query_id ) )
  308. {
  309. $result = @mysql_field_type( $query_id, $offset );
  310. $this->time += ( array_sum( explode( " ", microtime() ) ) - $stime );
  311. return $result;
  312. }
  313. $this->time += ( array_sum( explode( " ", microtime() ) ) - $stime );
  314. return false;
  315. }
  316. /**
  317. * sql_db::sql_fetchrow()
  318. *
  319. * @param integer $query_id
  320. * @param integer $type
  321. * @return
  322. */
  323. public function sql_fetchrow ( $query_id = 0, $type = 0 )
  324. {
  325. $stime = array_sum( explode( " ", microtime() ) );
  326. if ( empty( $query_id ) ) $query_id = $this->query_result;
  327. if ( ! empty( $query_id ) )
  328. {
  329. if ( $type != 1 and $type != 2 ) $type = 0;
  330. switch ( $type )
  331. {
  332. case 1:
  333. $this->row['' . $query_id . ''] = @mysql_fetch_array( $query_id, MYSQL_NUM );
  334. break;
  335. case 2:
  336. $this->row['' . $query_id . ''] = @mysql_fetch_array( $query_id, MYSQL_ASSOC );
  337. break;
  338. default:
  339. $this->row['' . $query_id . ''] = @mysql_fetch_array( $query_id, MYSQL_BOTH );
  340. }
  341. $this->time += ( array_sum( explode( " ", microtime() ) ) - $stime );
  342. return $this->row['' . $query_id . ''];
  343. }
  344. $this->time += ( array_sum( explode( " ", microtime() ) ) - $stime );
  345. return false;
  346. }
  347. /**
  348. * sql_db::sql_fetchrowset()
  349. *
  350. * @param integer $query_id
  351. * @return
  352. */
  353. public function sql_fetchrowset ( $query_id = 0 )
  354. {
  355. $stime = array_sum( explode( " ", microtime() ) );
  356. if ( empty( $query_id ) ) $query_id = $this->query_result;
  357. if ( ! empty( $query_id ) )
  358. {
  359. unset( $this->rowset['' . $query_id . ''] );
  360. unset( $this->row['' . $query_id . ''] );
  361. while ( $this->rowset['' . $query_id . ''] = @mysql_fetch_array( $query_id ) )
  362. {
  363. $result[] = $this->rowset['' . $query_id . ''];
  364. }
  365. $this->time += ( array_sum( explode( " ", microtime() ) ) - $stime );
  366. return $result;
  367. }
  368. $this->time += ( array_sum( explode( " ", microtime() ) ) - $stime );
  369. return false;
  370. }
  371. /**
  372. * sql_db::sql_fetchfield()
  373. *
  374. * @param mixed $field
  375. * @param integer $rownum
  376. * @param integer $query_id
  377. * @return
  378. */
  379. public function sql_fetchfield ( $field, $rownum = -1, $query_id = 0 )
  380. {
  381. if ( empty( $query_id ) ) $query_id = $this->query_result;
  382. $result = false;
  383. if ( ! empty( $query_id ) )
  384. {
  385. if ( $rownum > - 1 )
  386. {
  387. $result = @mysql_result( $query_id, $rownum, $field );
  388. }
  389. else
  390. {
  391. if ( empty( $this->row['' . $query_id . ''] ) && empty( $this->rowset['' . $query_id . ''] ) )
  392. {
  393. if ( $this->sql_fetchrow() ) $result = $this->row['' . $query_id . ''][$field];
  394. }
  395. else
  396. {
  397. if ( $this->rowset['' . $query_id . ''] )
  398. {
  399. $result = $this->rowset['' . $query_id . ''][$field];
  400. }
  401. elseif ( $this->row['' . $query_id . ''] )
  402. {
  403. $result = $this->row['' . $query_id . ''][$field];
  404. }
  405. }
  406. }
  407. }
  408. return $result;
  409. }
  410. /**
  411. * sql_db::sql_rowseek()
  412. *
  413. * @param mixed $rownum
  414. * @param integer $query_id
  415. * @return
  416. */
  417. public function sql_rowseek ( $rownum, $query_id = 0 )
  418. {
  419. if ( empty( $query_id ) ) $query_id = $this->query_result;
  420. if ( ! empty( $query_id ) )
  421. {
  422. $result = @mysql_data_seek( $query_id, $rownum );
  423. return $result;
  424. }
  425. return false;
  426. }
  427. /**
  428. * sql_db::sql_fetch_assoc()
  429. *
  430. * @param integer $query_id
  431. * @return
  432. */
  433. public function sql_fetch_assoc ( $query_id = 0 )
  434. {
  435. $stime = array_sum( explode( " ", microtime() ) );
  436. if ( empty( $query_id ) ) $query_id = $this->query_result;
  437. if ( ! empty( $query_id ) )
  438. {
  439. $this->row['' . $query_id . ''] = @mysql_fetch_assoc( $query_id );
  440. $this->time += ( array_sum( explode( " ", microtime() ) ) - $stime );
  441. return $this->row['' . $query_id . ''];
  442. }
  443. $this->time += ( array_sum( explode( " ", microtime() ) ) - $stime );
  444. return false;
  445. }
  446. /**
  447. * sql_db::sql_freeresult()
  448. *
  449. * @param integer $query_id
  450. * @return
  451. */
  452. public function sql_freeresult ( $query_id = 0 )
  453. {
  454. if ( empty( $query_id ) ) $query_id = $this->query_result;
  455. if ( is_resource( $query_id ) )
  456. {
  457. unset( $this->row['' . $query_id . ''] );
  458. unset( $this->rowset['' . $query_id . ''] );
  459. @mysql_free_result( $query_id );
  460. return true;
  461. }
  462. return false;
  463. }
  464. /**
  465. * sql_db::sql_error()
  466. *
  467. * @param string $message
  468. * @return
  469. */
  470. public function sql_error ( $message = '' )
  471. {
  472. if ( ! $this->db_connect_id )
  473. {
  474. return array(
  475. 'message' => @mysql_error(), 'user_message' => $message, 'code' => @mysql_errno()
  476. );
  477. }
  478. return array(
  479. 'message' => @mysql_error( $this->db_connect_id ), 'user_message' => $message, 'code' => @mysql_errno( $this->db_connect_id )
  480. );
  481. }
  482. /**
  483. * sql_db::fixdb()
  484. *
  485. * @param mixed $value
  486. * @return
  487. */
  488. public function fixdb ( $value )
  489. {
  490. $value = str_replace( '\'', '&#039;', $value );
  491. $value = preg_replace( array(
  492. "/(se)(lect)/i", "/(uni)(on)/i", "/(con)(cat)/i", "/(c)(har)/i", "/(out)(file)/i", "/(al)(ter)/i", "/(in)(sert)/i", "/(d)(rop)/i", "/(f)(rom)/i", "/(whe)(re)/i", "/(up)(date)/i", "/(de)(lete)/i", "/(cre)(ate)/i"
  493. ), "$1-$2", $value );
  494. return $value;
  495. }
  496. /**
  497. * sql_db::unfixdb()
  498. *
  499. * @param mixed $value
  500. * @return
  501. */
  502. function unfixdb ( $value )
  503. {
  504. $value = preg_replace( array(
  505. "/(se)\-(lect)/i", "/(uni)\-(on)/i", "/(con)\-(cat)/i", "/(c)\-(har)/i", "/(out)\-(file)/i", "/(al)\-(ter)/i", "/(in)\-(sert)/i", "/(d)\-(rop)/i", "/(f)\-(rom)/i", "/(whe)\-(re)/i", "/(up)\-(date)/i", "/(de)\-(lete)/i", "/(cre)\-(ate)/i"
  506. ), "$1$2", $value );
  507. return $value;
  508. }
  509. /**
  510. * sql_db::dbescape()
  511. *
  512. * @param mixed $value
  513. * @return
  514. */
  515. public function dbescape ( $value )
  516. {
  517. if ( is_array( $value ) )
  518. {
  519. $value = array_map( array(
  520. $this, __function__
  521. ), $value );
  522. }
  523. else
  524. {
  525. if ( ! is_numeric( $value ) || $value{0} == '0' )
  526. {
  527. $value = "'" . mysql_real_escape_string( $this->fixdb( $value ) ) . "'";
  528. }
  529. }
  530. return $value;
  531. }
  532. /**
  533. * sql_db::dbescape_string()
  534. *
  535. * @param mixed $value
  536. * @return
  537. */
  538. public function dbescape_string ( $value )
  539. {
  540. if ( is_array( $value ) )
  541. {
  542. $value = array_map( array(
  543. $this, __function__
  544. ), $value );
  545. }
  546. else
  547. {
  548. $value = "'" . mysql_real_escape_string( $this->fixdb( $value ) ) . "'";
  549. }
  550. return $value;
  551. }
  552. /**
  553. * sql_db::nv_dblikeescape()
  554. *
  555. * @param mixed $value
  556. * @return
  557. */
  558. public function dblikeescape ( $value )
  559. {
  560. if ( is_array( $value ) )
  561. {
  562. $value = array_map( array(
  563. $this, __function__
  564. ), $value );
  565. }
  566. else
  567. {
  568. $value = mysql_real_escape_string( $this->fixdb( $value ) );
  569. $value = addcslashes( $value, '_%' );
  570. }
  571. return $value;
  572. }
  573. /**
  574. * sql_db::constructQuery()
  575. *
  576. * @return
  577. */
  578. public function constructQuery ( )
  579. {
  580. $numargs = func_num_args();
  581. if ( empty( $numargs ) ) return false;
  582. $pattern = func_get_arg( 0 );
  583. if ( empty( $pattern ) ) return false;
  584. unset( $matches );
  585. $pattern = preg_replace( "/[\n\r\t]/", " ", $pattern );
  586. $pattern = preg_replace( "/[ ]+/", " ", $pattern );
  587. $pattern = preg_replace( array(
  588. "/([\S]+)\[/", "/\]([\S]+)/", "/\[[\s]+/", "/[\s]+\]/", "/[\s]*\,[\s]*/"
  589. ), array(
  590. "\\1 [", "] \\1", "[", "]", ", "
  591. ), $pattern );
  592. preg_match_all( "/[\s]*[\"|\']*[\s]*\[([s|d])([a]*)\][\s]*[\"|\']*[\s]*/", $pattern, $matches );
  593. $replacement = func_get_args();
  594. unset( $replacement[0] );
  595. $count1 = count( $matches[0] );
  596. $count2 = count( $replacement );
  597. if ( ! empty( $count1 ) )
  598. {
  599. if ( $count2 < $count1 ) return false;
  600. $replacement = array_values( $replacement );
  601. $pattern = str_replace( "%", "[:25:]", $pattern );
  602. $pattern = preg_replace( "/[\s]*[\"|\']*[\s]*\[([s|d])([a]*)\][\s]*[\"|\']*[\s]*/", " %s ", $pattern );
  603. $repls = array();
  604. foreach ( $matches[1] as $key => $datatype )
  605. {
  606. $repls[$key] = $replacement[$key];
  607. if ( $datatype == 's' )
  608. {
  609. if ( isset( $matches[2][$key] ) and $matches[2][$key] == 'a' )
  610. {
  611. $repls[$key] = ( array )$repls[$key];
  612. if ( ! empty( $repls[$key] ) )
  613. {
  614. $repls[$key] = array_map( array(
  615. $this, 'fixdb'
  616. ), $repls[$key] );
  617. $repls[$key] = array_map( 'mysql_real_escape_string', $repls[$key] );
  618. $repls[$key] = "'" . implode( "','", $repls[$key] ) . "'";
  619. }
  620. else
  621. {
  622. $repls[$key] = "''";
  623. }
  624. }
  625. else
  626. {
  627. $repls[$key] = "'" . ( ! empty( $repls[$key] ) ? mysql_real_escape_string( $this->fixdb( $repls[$key] ) ) : "" ) . "'";
  628. }
  629. }
  630. else
  631. {
  632. if ( isset( $matches[2][$key] ) and $matches[2][$key] == 'a' )
  633. {
  634. $repls[$key] = ( array )$repls[$key];
  635. $repls[$key] = ( ! empty( $repls[$key] ) ) ? "'" . implode( "','", array_map( 'intval', $repls[$key] ) ) . "'" : "'0'";
  636. }
  637. else
  638. {
  639. $repls[$key] = "'" . intval( $repls[$key] ) . "'";
  640. }
  641. }
  642. }
  643. eval( "\$query = sprintf(\$pattern,\"" . implode( "\",\"", $repls ) . "\");" );
  644. $query = str_replace( "[:25:]", "%", $query );
  645. }
  646. else
  647. {
  648. $query = $pattern;
  649. }
  650. return $query;
  651. }
  652. }
  653. ?>