Advertisement
Guest User

Untitled

a guest
Jan 25th, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 34.46 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  
  5. * Database Class provides a consistent API to communicate with MySQL or Oracle Databases.
  6.  
  7. * This one implements the MySQL API.
  8.  
  9. * @package db_MySQL
  10.  
  11. * @version 0.1 (07-Apr-2009)
  12.  
  13. * @filesource
  14.  
  15. */
  16.  
  17. /**
  18.  
  19. * Main class definition.
  20.  
  21. * @package db_MySQL
  22.  
  23. */
  24.  
  25. class db_MySQL
  26.  
  27. {
  28.  
  29. /** @var mixed $sock Internal connection handle */
  30.  
  31. var $sock;
  32.  
  33. /** @var string $host Name of database to connect to */
  34.  
  35. var $host;
  36.  
  37. /** @var integer $port Portnumber to use when connecting to MySQL */
  38.  
  39. var $port;
  40.  
  41. /** @var string $user Name of database user used for connection */
  42.  
  43. var $user;
  44.  
  45. /** @var string $password Password of database user used for connection */
  46.  
  47. var $password;
  48.  
  49. /** @var string $database Name of schema to be used */
  50.  
  51. var $database;
  52.  
  53. /** @var integer $num_rows Counts total number of records fetched */
  54.  
  55. var $num_rows;
  56.  
  57. /** @var integer $querycounter Counts the processed queries against the database */
  58.  
  59. var $querycounter;
  60.  
  61. /** @var float $querytime Contains the total SQL execution time in microseconds. */
  62.  
  63. var $querytime;
  64.  
  65. /** @var string $appname Name of Application that uses this class */
  66.  
  67. var $appname;
  68.  
  69. /** @var string $classversion Version of this class in format VER.REV */
  70.  
  71. var $classversion;
  72.  
  73. /** @var string $currentQuery Contains the actual query to be processed. */
  74.  
  75. var $currentQuery;
  76.  
  77. /** @var integer $showError Flag indicates how the class should interact with errors */
  78.  
  79. var $showError;
  80.  
  81. /** @var integer $debug Flag indicates debug mode of class */
  82.  
  83. var $debug;
  84.  
  85. /** @var string $SAPI_type The SAPI type of php (used to detect CLI sapi) */
  86.  
  87. var $SAPI_type;
  88.  
  89. /** @var string $AdminEmail Email Address for the administrator of this project */
  90.  
  91. var $AdminEmail;
  92.  
  93. /** @var integer $myErrno Error code of last mysql operation (set in Print_Error()) */
  94.  
  95. var $myErrno;
  96.  
  97. /** @var string $myErrStr Error string of last mysql operation (set in Print_Error()) */
  98.  
  99. var $myErrStr;
  100.  
  101. /** @var boolean $usePConnect TRUE = Connect() uses Persistant connection, else new one (Default) */
  102.  
  103. var $usePConnect;
  104.  
  105. /** @var string $character_set Character set to use. */
  106.  
  107. var $character_set;
  108.  
  109. /** @var string $locale Locale to use for DATE_FORMAT(), DAYNAME() and MONTHNAME() SQL functions. */
  110.  
  111. var $locale;
  112.  
  113.  
  114.  
  115. /**
  116.  
  117. * Constructor of this class.
  118.  
  119. * The constructor takes default values from dbdefs.inc.php.
  120.  
  121. * Please see this file for further informations about the setable options.
  122.  
  123. * @param string $extconfig Optional other filename for dbdefs.inc.php, defaults to "dbdefs.inc.php".
  124.  
  125. * @see dbdefs.inc.php
  126.  
  127. */
  128.  
  129. function db_MySQL($extconfig='')
  130.  
  131. {
  132.  
  133. if($extconfig == '')
  134.  
  135. {
  136.  
  137. require_once(DOC.'/includes/config.php');
  138.  
  139. }
  140.  
  141. else
  142.  
  143. {
  144.  
  145. require($extconfig);
  146.  
  147. }
  148.  
  149. $this->classversion = '0.36';
  150.  
  151.  
  152.  
  153. $this->host = '';
  154.  
  155. $this->port = 3306;
  156.  
  157. $this->user = '';
  158.  
  159. $this->pass = '';
  160.  
  161. $this->database = '';
  162.  
  163. $this->appname = MYSQLAPPNAME;
  164.  
  165.  
  166.  
  167. $this->sock = 0;
  168.  
  169. $this->querycounter = 0;
  170.  
  171. $this->querytime = 0.000;
  172.  
  173. $this->currentQuery = '';
  174.  
  175. $this->debug = 0;
  176.  
  177. $this->myErrno = 0;
  178.  
  179. $this->MyErrStr = '';
  180.  
  181. // $this->AdminEmail = $_SERVER['SERVER_ADMIN']; // Defaults to Webadministrator of Server
  182.  
  183. $this->SAPI_type = @php_sapi_name(); // May contain 'cli', in this case disable HTML errors!
  184.  
  185. $this->usePConnect = FALSE; // Set to TRUE to use Persistant connections
  186.  
  187. $this->characterset = ''; // Will be filled from define MYSQLDB_CHARACTERSET during Connect()
  188.  
  189. $this->locale = ''; // Will be filled from define MYSQLDB_TIME_NAMES during Connect()
  190.  
  191.  
  192.  
  193. if(!defined('MYSQLAPPNAME'))
  194.  
  195. {
  196.  
  197. $this->setErrorHandling(DBOF_SHOW_ALL_ERRORS);
  198.  
  199. $this->Print_Error('config.php not found/wrong configured! Please check Class installation!');
  200.  
  201. }
  202.  
  203.  
  204.  
  205. if(defined('DB_ERRORMODE')) // You can set a default behavour for error handling in debdefs.inc.php
  206.  
  207. {
  208.  
  209. $this->setErrorHandling(DB_ERRORMODE);
  210.  
  211. }
  212.  
  213. else
  214.  
  215. {
  216.  
  217. $this->setErrorHandling(DBOF_SHOW_NO_ERRORS); // Default is not to show too much informations
  218.  
  219. }
  220.  
  221.  
  222.  
  223. if(defined('MYSQLDB_ADMINEMAIL'))
  224.  
  225. {
  226.  
  227. $this->AdminEmail = MYSQLDB_ADMINEMAIL; // If set use this address instead of default webmaster
  228.  
  229. }
  230.  
  231.  
  232.  
  233. // Check if user requested persistant connection per default in dbdefs.inc.php
  234.  
  235.  
  236.  
  237. if(defined('MYSQLDB_USE_PCONNECT') && MYSQLDB_USE_PCONNECT != 0)
  238.  
  239. {
  240.  
  241. $this->usePConnect = TRUE;
  242.  
  243. }
  244.  
  245.  
  246.  
  247. // Check if user wants to have set a specific character set with 'SET NAMES <cset>'
  248.  
  249.  
  250.  
  251. if(defined('MYSQLDB_CHARACTERSET') && MYSQLDB_CHARACTERSET != '')
  252.  
  253. {
  254.  
  255. $this->characterset = MYSQLDB_CHARACTERSET;
  256.  
  257. }
  258.  
  259.  
  260.  
  261. // Check if user wants to have set a specific locale with 'SET SET lc_time_names = <locale>;'
  262.  
  263.  
  264.  
  265. if(defined('MYSQLDB_TIME_NAMES') && MYSQLDB_TIME_NAMES != '')
  266.  
  267. {
  268.  
  269. $this->locale = MYSQLDB_TIME_NAMES;
  270.  
  271. }
  272.  
  273. }
  274.  
  275.  
  276.  
  277. /**
  278.  
  279. * Performs the connection to MySQL.
  280.  
  281. * If anything goes wrong calls Print_Error().
  282.  
  283. * You should set the defaults for your connection by setting
  284.  
  285. * user,pass,host and database in dbdefs.inc.php and leave
  286.  
  287. * connect() parameters empty.
  288.  
  289. * If MYSQLDB_CHARACTERSET define is set a "SET NAMES '<charset>'; is used straight after connecting.
  290.  
  291. * @param string $user Username used to connect to DB
  292.  
  293. * @param string $pass Password to use for given username
  294.  
  295. * @param string $host Hostname of database to connect to
  296.  
  297. * @param integer $port TCP port to use for connection. Defaults to 3306.
  298.  
  299. * @param string $db Schema to use on MySQL DB Server
  300.  
  301. * @return mixed Either the DB connection handle or NULL in case of an error.
  302.  
  303. * @see dbdefs.inc.php
  304.  
  305. * @see mysql_connect
  306.  
  307. * @see mysql_pconnect
  308.  
  309. * @see mysql_select_db
  310.  
  311. */
  312.  
  313. function Connect($user='',$pass='',$host='',$db='',$port = 0)
  314.  
  315. {
  316.  
  317. if($this->sock)
  318.  
  319. {
  320.  
  321. return($this->sock);
  322.  
  323. }
  324.  
  325. if($user!='')
  326.  
  327. {
  328.  
  329. $this->user = $user;
  330.  
  331. }
  332.  
  333. else
  334.  
  335. {
  336.  
  337. $this->user = MYSQLDB_USER;
  338.  
  339. }
  340.  
  341. if($pass!='')
  342.  
  343. {
  344.  
  345. $this->pass = $pass;
  346.  
  347.  
  348. }
  349.  
  350. else
  351.  
  352. {
  353.  
  354. $this->pass = MYSQLDB_PASS;
  355.  
  356. }
  357.  
  358. if($host!='')
  359.  
  360. {
  361.  
  362. $this->host = $host;
  363.  
  364. }
  365.  
  366. else
  367.  
  368. {
  369.  
  370. $this->host = MYSQLDB_HOST;
  371.  
  372. }
  373.  
  374. if($db!='')
  375.  
  376. {
  377.  
  378. $this->database = $db;
  379.  
  380. }
  381.  
  382. else
  383.  
  384. {
  385.  
  386. $this->database = MYSQLDB_DATABASE;
  387.  
  388. }
  389.  
  390. if(!$port)
  391.  
  392. {
  393.  
  394. if(defined('MYSQLDB_PORT'))
  395.  
  396. {
  397.  
  398. $this->port = MYSQLDB_PORT;
  399.  
  400. }
  401.  
  402. else
  403.  
  404. {
  405.  
  406. $this->port = 3306;
  407.  
  408. }
  409.  
  410. }
  411.  
  412. else
  413.  
  414. {
  415.  
  416. $this->port = $port;
  417.  
  418. }
  419.  
  420. // Append port number ONLY if hostname doesn't start with a slash (which is a pipe!)
  421.  
  422. if(strlen($this->host) >= 1 && $this->host[0] != '/')
  423.  
  424. {
  425.  
  426. $this->host.':'.$this->port;
  427.  
  428. }
  429.  
  430.  
  431.  
  432. $start = $this->getmicrotime();
  433.  
  434. $this->printDebug('mysql_connect('.sprintf("%s/%s@%s",$this->user,$this->pass,$this->host).')');
  435.  
  436. if($this->usePConnect == FALSE)
  437.  
  438. {
  439.  
  440. if(version_compare('4.3.0',@phpversion()) < 0)
  441.  
  442. {
  443.  
  444. $this->sock = @mysql_connect($this->host,$this->user,$this->pass);
  445.  
  446.  
  447. }
  448.  
  449. else
  450.  
  451. {
  452.  
  453. $this->sock = @mysql_connect($this->host,$this->user,$this->pass);
  454.  
  455. }
  456.  
  457. }
  458.  
  459. else // Persistant connection requested:
  460.  
  461. {
  462.  
  463. if(version_compare('4.3.0',@phpversion()) < 0)
  464.  
  465. {
  466.  
  467. $this->sock = @mysql_pconnect($this->host,$this->user,$this->pass);
  468.  
  469. }
  470.  
  471. else
  472.  
  473. {
  474.  
  475. $this->sock = @mysql_pconnect($this->host,$this->user,$this->pass);
  476.  
  477. }
  478.  
  479. }
  480.  
  481. if(!$this->sock)
  482.  
  483. {
  484.  
  485. $this->Print_Error('Connect(): Connection to '.$this->host.' failed!');
  486.  
  487. return(0);
  488.  
  489. }
  490.  
  491. if(!@mysql_select_db($this->database,$this->sock))
  492.  
  493. {
  494.  
  495. $this->Print_Error('Connect(): SelectDB(\''.$this->database.'\') failed!');
  496.  
  497. return(0);
  498.  
  499. }
  500.  
  501. $this->querytime+= ($this->getmicrotime() - $start);
  502.  
  503. if($this->characterset != '')
  504.  
  505. {
  506.  
  507. $rc = $this->Query("SET NAMES '".$this->characterset."'",MYSQL_NUM,1);
  508.  
  509. if($rc != 1)
  510.  
  511. {
  512.  
  513. $this->Print_Error('Connect(): Error while trying to set character set "'.$this->characterset.'" !!!');
  514.  
  515. return(0);
  516.  
  517. }
  518.  
  519. }
  520.  
  521. if($this->locale != '')
  522.  
  523. {
  524.  
  525. $rc = $this->Query("SET lc_time_names='".$this->locale."'",MYSQL_NUM,1);
  526.  
  527. if($rc != 1)
  528.  
  529. {
  530.  
  531. $this->Print_Error('Connect(): Error while trying to set lc_time_names to "'.$this->locale.'" !!!');
  532.  
  533. return(0);
  534.  
  535. }
  536.  
  537. }
  538.  
  539. return($this->sock);
  540.  
  541. }
  542.  
  543.  
  544.  
  545. /**
  546.  
  547. * Disconnects from MySQL.
  548.  
  549. * You may optionally pass an external link identifier.
  550.  
  551. * @param mixed $other_sock Optionally your own connection handle to close, else internal will be used
  552.  
  553. * @see mysql_close
  554.  
  555. */
  556.  
  557. function Disconnect($other_sock=-1)
  558.  
  559. {
  560.  
  561. if($other_sock!=-1)
  562.  
  563. {
  564.  
  565. @mysql_close($other_sock);
  566.  
  567. }
  568.  
  569. else
  570.  
  571. {
  572.  
  573. if($this->sock)
  574.  
  575. {
  576.  
  577. @mysql_close($this->sock);
  578.  
  579. $this->sock = 0;
  580.  
  581. }
  582.  
  583. }
  584.  
  585. $this->currentQuery = '';
  586.  
  587. }
  588.  
  589.  
  590.  
  591. /**
  592.  
  593. * Prints out MySQL Error in own <div> container and exits.
  594.  
  595. * Please note that this function does not return as long as you have not set DBOF_RETURN_ALL_ERRORS!
  596.  
  597. * @param string $ustr User-defined Error string to show
  598.  
  599. * @param mixed $var2dump Optionally a variable to print out with print_r()
  600.  
  601. * @see print_r
  602.  
  603. * @see mysql_errno
  604.  
  605. * @see mysql_error
  606.  
  607. */
  608.  
  609. function Print_Error($ustr="",$var2dump="")
  610.  
  611. {
  612.  
  613. $errnum = @mysql_errno();
  614.  
  615. $errstr = @mysql_error();
  616.  
  617. $filename = basename($_SERVER['SCRIPT_FILENAME']);
  618.  
  619. $this->myErrno = $errnum;
  620.  
  621. $this->myErrStr= $errstr;
  622.  
  623. if($errstr=='')
  624.  
  625. {
  626.  
  627. $errstr = 'N/A';
  628.  
  629. }
  630.  
  631. if($errnum=='')
  632.  
  633. {
  634.  
  635. $errnum = -1;
  636.  
  637. }
  638.  
  639. @error_log($this->appname.': Error in '.$filename.': '.$ustr.' ('.chop($errstr).')',0);
  640.  
  641. if($this->showError == DBOF_RETURN_ALL_ERRORS)
  642.  
  643. {
  644.  
  645. return($errnum); // Return the error number
  646.  
  647. }
  648.  
  649. $this->SendMailOnError($errnum,$errstr,$ustr);
  650.  
  651. $crlf = "\n";
  652.  
  653. $space= " ";
  654.  
  655. if($this->SAPI_type != 'cli')
  656.  
  657. {
  658.  
  659. $crlf = "<br>\n";
  660.  
  661. $space= "&nbsp;";
  662.  
  663. echo("<br>\n<div align=\"left\" style=\"background-color: #EEEEEE; color:#000000\" class=\"TB\">\n");
  664.  
  665. echo("<font color=\"red\" face=\"Arial, Sans-Serif\"><b>".$this->appname.": Database Error occured!</b></font><br>\n<br>\n<code>\n");
  666.  
  667. }
  668.  
  669. else
  670.  
  671. {
  672.  
  673. echo("\n!!! ".$this->appname.": Database Error occured !!!\n\n");
  674.  
  675. }
  676.  
  677. echo($space."CODE: ".$errnum.$crlf);
  678.  
  679. echo($space."DESC: ".$errstr.$crlf);
  680.  
  681. echo($space."FILE: ".$filename.$crlf);
  682.  
  683. if($this->showError == DBOF_SHOW_ALL_ERRORS)
  684.  
  685. {
  686.  
  687. if($this->currentQuery!="")
  688.  
  689. {
  690.  
  691. echo("QUERY: ".$this->currentQuery.$crlf);
  692.  
  693. }
  694.  
  695. echo($space."QCNT: ".$this->querycounter.$crlf);
  696.  
  697. if($ustr!='')
  698.  
  699. {
  700.  
  701. echo($space."INFO: ".$ustr.$crlf);
  702.  
  703. }
  704.  
  705. if($var2dump!='')
  706.  
  707. {
  708.  
  709. echo($space.'DUMP: ');
  710.  
  711. if(is_array($var2dump))
  712.  
  713. {
  714.  
  715. if($this->SAPI_type != 'cli')
  716.  
  717. {
  718.  
  719. echo('<pre>');
  720.  
  721. print_r($var2dump);
  722.  
  723. echo("</pre>\n");
  724.  
  725. }
  726.  
  727. else
  728.  
  729. {
  730.  
  731. print_r($var2dump);
  732.  
  733. }
  734.  
  735. }
  736.  
  737. else
  738.  
  739. {
  740.  
  741. echo($var2dump.$crlf);
  742.  
  743. }
  744.  
  745. }
  746.  
  747. }
  748.  
  749. if($this->SAPI_type != 'cli')
  750.  
  751. {
  752.  
  753. echo("<br>\nPlease inform <a href=\"mailto:".$this->AdminEmail."\">".$this->AdminEmail."</a> about this problem.");
  754.  
  755. echo("</code>\n");
  756.  
  757. echo("</div>\n");
  758.  
  759. echo("<div align=\"right\"><small>PHP v".phpversion()." / MySQL Class v".$this->classversion."</small></div>\n");
  760.  
  761. }
  762.  
  763. else
  764.  
  765. {
  766.  
  767. echo("\nPlease inform ".$this->AdminEmail." about this problem.\n\nRunning on PHP V".phpversion()." / MySQL Class v".$this->classversion."\n");
  768.  
  769. }
  770.  
  771. $this->Disconnect();
  772.  
  773. exit;
  774.  
  775. }
  776.  
  777.  
  778.  
  779. /**
  780.  
  781. * Performs a single row query.
  782.  
  783. *
  784.  
  785. * Resflag can be MYSQL_NUM or MYSQL_ASSOC
  786.  
  787. * depending on what kind of array you want to be returned.
  788.  
  789. * @param string $querystring The query to be executed
  790.  
  791. * @param integer $resflag Decides how the result should be returned:
  792.  
  793. * - MYSQL_ASSOC = Data is returned as assoziative array
  794.  
  795. * - MYSQL_NUM = Data is returned as numbered array
  796.  
  797. * @param integer $no_exit Decides how the class should react on errors.
  798.  
  799. * If you set this to 1 the class won't automatically exit
  800.  
  801. * on an error but instead return the mysql_errno value.
  802.  
  803. * Default of 0 means that the class calls Print_Error()
  804.  
  805. * and exists.
  806.  
  807. * @return mixed Either the result of the query or an error code or no return value at all
  808.  
  809. * @see Print_Error
  810.  
  811. * @see mysql_query
  812.  
  813. * @see mysql_fetch_array
  814.  
  815. * @see mysql_free_result
  816.  
  817. */
  818.  
  819. function Query($querystring,$resflag = MYSQL_ASSOC, $no_exit = 0)
  820.  
  821. {
  822.  
  823. if(!$this->sock)
  824.  
  825. {
  826.  
  827. return($this->Print_Error('Query(): No active Connection!',$querystring));
  828.  
  829. }
  830.  
  831. if($this->debug)
  832.  
  833. {
  834.  
  835. $this->PrintDebug($querystring);
  836.  
  837. }
  838.  
  839. $this->currentQuery = $querystring;
  840.  
  841. if($this->showError == DBOF_RETURN_ALL_ERRORS)
  842.  
  843. {
  844.  
  845. $no_exit = 1; // Override if user has set master define
  846.  
  847. }
  848.  
  849. $start = $this->getmicrotime();
  850.  
  851. $res = @mysql_query($querystring,$this->sock);
  852.  
  853. if($res == false)
  854.  
  855. {
  856.  
  857. if($no_exit)
  858.  
  859. {
  860.  
  861. $reterror = @mysql_errno();
  862.  
  863. return($reterror);
  864.  
  865. }
  866.  
  867. else
  868.  
  869. {
  870.  
  871. return($this->Print_Error("Query('".$querystring."') failed!"));
  872.  
  873. }
  874.  
  875. }
  876.  
  877. $this->querycounter++;
  878.  
  879. // Check if query requires returning the results or just the result of the query call:
  880.  
  881. if( StriStr($querystring,'SELECT ') ||
  882.  
  883. StriStr($querystring,'SHOW ') ||
  884.  
  885. StriStr($querystring,'EXPLAIN ') ||
  886.  
  887. StriStr($querystring,'DESCRIBE ') ||
  888.  
  889. StriStr($querystring,'OPTIMIZE ') ||
  890.  
  891. StriStr($querystring,'ANALYZE ') ||
  892.  
  893. StriStr($querystring,'CHECK ')
  894.  
  895. )
  896.  
  897. {
  898.  
  899. $this->num_rows=mysql_num_rows($res);
  900.  
  901. $retdata = @mysql_fetch_array($res,$resflag);
  902.  
  903.  
  904.  
  905. @mysql_free_result($res);
  906.  
  907. $this->querytime+= ($this->getmicrotime() - $start);
  908.  
  909. return($retdata);
  910.  
  911. }
  912.  
  913. else
  914.  
  915. {
  916.  
  917. $this->querytime+= ($this->getmicrotime() - $start);
  918.  
  919. return($res);
  920.  
  921. }
  922.  
  923. }
  924.  
  925.  
  926.  
  927.  
  928.  
  929. /**
  930.  
  931. * Performs a multi-row query and returns result identifier.
  932.  
  933. * @param string $querystring The Query to be executed
  934.  
  935. * @param integer $no_exit The error indicator flag, can be one of:
  936.  
  937. * - 0 = (Default), In case of an error Print_Error is called and script terminates
  938.  
  939. * - 1 = In case of an error this function returns the error from mysql_errno()
  940.  
  941. * @return mixed A resource identifier or an errorcode (if $no_exit = 1)
  942.  
  943. * @see mysql_query
  944.  
  945. */
  946.  
  947. function QueryResult($querystring, $no_exit = 0)
  948.  
  949. {
  950.  
  951. if(!$this->sock)
  952.  
  953. {
  954.  
  955. return($this->Print_Error('QueryResult(): No active Connection!',$querystring));
  956.  
  957. }
  958.  
  959. if($this->debug)
  960.  
  961. {
  962.  
  963. $this->PrintDebug($querystring);
  964.  
  965. }
  966.  
  967. $this->currentQuery = $querystring;
  968.  
  969. $start = $this->getmicrotime();
  970.  
  971. $res = @mysql_query($querystring,$this->sock);
  972.  
  973. $this->querycounter++;
  974.  
  975. if($res == false)
  976.  
  977. {
  978.  
  979. if($no_exit)
  980.  
  981. {
  982.  
  983. $reterror = @mysql_errno();
  984.  
  985. $this->querytime+= ($this->getmicrotime() - $start);
  986.  
  987. return($reterror);
  988.  
  989. }
  990.  
  991. else
  992.  
  993. {
  994.  
  995. return($this->Print_Error("QueryResult('".$querystring."') failed!"));
  996.  
  997. }
  998.  
  999. }
  1000.  
  1001. $this->querytime+= ($this->getmicrotime() - $start);
  1002.  
  1003. return($res);
  1004.  
  1005. }
  1006.  
  1007.  
  1008.  
  1009. /**
  1010.  
  1011. * Fetches next row from result handle.
  1012.  
  1013. * Returns either numeric (MYSQL_NUM) or associative (MYSQL_ASSOC) array
  1014.  
  1015. * for one data row as pointed to by result var.
  1016.  
  1017. * @param mixed $result The resource identifier as returned by QueryResult()
  1018.  
  1019. * @param integer $resflag How you want the data to be returned:
  1020.  
  1021. * - MYSQL_ASSOC = Data is returned as assoziative array
  1022.  
  1023. * - MYSQL_NUM = Data is returned as numbered array
  1024.  
  1025. * @return array One row of the resulting query or NULL if there are no data anymore
  1026.  
  1027. * @see mysql_fetch_array
  1028.  
  1029. * @see QueryResult
  1030.  
  1031. */
  1032.  
  1033. function FetchResult($result,$resflag = MYSQL_ASSOC)
  1034.  
  1035. {
  1036.  
  1037. if(!$result)
  1038.  
  1039. {
  1040.  
  1041. return($this->Print_Error('FetchResult(): No valid result handle!'));
  1042.  
  1043. }
  1044.  
  1045. $start = $this->getmicrotime();
  1046.  
  1047. $resar = @mysql_fetch_array($result,$resflag);
  1048.  
  1049. $this->querytime+= ($this->getmicrotime() - $start);
  1050.  
  1051. return($resar);
  1052.  
  1053. }
  1054.  
  1055.  
  1056.  
  1057. /**
  1058.  
  1059. * This function is used to fetch all rows for the given query
  1060.  
  1061. * @param string $querystring The Query to be executed
  1062.  
  1063. * return array of results
  1064.  
  1065. **/
  1066.  
  1067. function FetchAllResults($querystring){
  1068.  
  1069. $result=$this->QueryResult($querystring, $no_exit = 0);
  1070.  
  1071. $resultarr=array();
  1072.  
  1073. $i=0;
  1074.  
  1075. while($resar = @mysql_fetch_array($result,MYSQL_ASSOC)){
  1076.  
  1077. foreach ($resar as $key => $val) {
  1078.  
  1079. $resultarr[$i][$key]= $val;
  1080.  
  1081. }
  1082.  
  1083. $i++;
  1084.  
  1085. }
  1086.  
  1087.  
  1088.  
  1089. return $resultarr;
  1090.  
  1091. }
  1092.  
  1093. /**
  1094.  
  1095. * Frees result returned by QueryResult().
  1096.  
  1097. * It is a good programming practise to give back what you have taken, so after processing
  1098.  
  1099. * your Multi-Row query with FetchResult() finally call this function to free the allocated
  1100.  
  1101. * memory.
  1102.  
  1103. *
  1104.  
  1105. * @param mixed $result The resource identifier you want to be freed.
  1106.  
  1107. * @return mixed The resulting code of mysql_free_result (can be ignored).
  1108.  
  1109. * @see mysql_free_result
  1110.  
  1111. * @see QueryResult
  1112.  
  1113. * @see FetchResult
  1114.  
  1115. */
  1116.  
  1117. function FreeResult($result)
  1118.  
  1119. {
  1120.  
  1121. $this->currentQuery = '';
  1122.  
  1123. $start = $this->getmicrotime();
  1124.  
  1125. $myres = @mysql_free_result($result);
  1126.  
  1127. $this->querytime+= ($this->getmicrotime() - $start);
  1128.  
  1129. return($myres);
  1130.  
  1131. }
  1132.  
  1133.  
  1134.  
  1135. /**
  1136.  
  1137. * Returns MySQL Server Version.
  1138.  
  1139. * Opens an own connection if no active one exists.
  1140.  
  1141. * @return string MySQL Server Version
  1142.  
  1143. */
  1144.  
  1145. function Version()
  1146.  
  1147. {
  1148.  
  1149. $weopen = 0;
  1150.  
  1151. if(!$this->sock)
  1152.  
  1153. {
  1154.  
  1155. $this->connect();
  1156.  
  1157. $weopen = 1;
  1158.  
  1159. }
  1160.  
  1161. $ver = $this->Query('SELECT VERSION()',MYSQL_NUM);
  1162.  
  1163. if($weopen)
  1164.  
  1165. {
  1166.  
  1167. $this->Disconnect();
  1168.  
  1169. }
  1170.  
  1171. return($ver[0]);
  1172.  
  1173. }
  1174.  
  1175.  
  1176.  
  1177. /**
  1178.  
  1179. * Returns amount of queries executed by this class.
  1180.  
  1181. * @return integer Querycount
  1182.  
  1183. */
  1184.  
  1185. function GetQueryCount()
  1186.  
  1187. {
  1188.  
  1189. return($this->querycounter);
  1190.  
  1191. }
  1192.  
  1193.  
  1194.  
  1195. /**
  1196.  
  1197. * Returns amount of time spend on queries executed by this class.
  1198.  
  1199. * @return float Time in seconds.msecs spent in executin MySQL code.
  1200.  
  1201. */
  1202.  
  1203. function GetQueryTime()
  1204.  
  1205. {
  1206.  
  1207. return($this->querytime);
  1208.  
  1209. }
  1210.  
  1211.  
  1212.  
  1213. /**
  1214.  
  1215. * Commits current transaction.
  1216.  
  1217. * Note: Requires transactional tables, else does nothing!
  1218.  
  1219. */
  1220.  
  1221. function Commit()
  1222.  
  1223. {
  1224.  
  1225. if($this->debug)
  1226.  
  1227. {
  1228.  
  1229. $this->PrintDebug('COMMIT called');
  1230.  
  1231. }
  1232.  
  1233. $this->Query('COMMIT;');
  1234.  
  1235. }
  1236.  
  1237.  
  1238.  
  1239. /**
  1240.  
  1241. * Rollback current transaction.
  1242.  
  1243. * Note: Requires transactional tables, else does nothing!
  1244.  
  1245. */
  1246.  
  1247. function Rollback()
  1248.  
  1249. {
  1250.  
  1251. if($this->debug)
  1252.  
  1253. {
  1254.  
  1255. $this->PrintDebug('ROLLBACK called');
  1256.  
  1257. }
  1258.  
  1259. $this->Query('ROLLBACK;');
  1260.  
  1261. }
  1262.  
  1263.  
  1264.  
  1265. /**
  1266.  
  1267. * Function allows debugging of SQL Queries.
  1268.  
  1269. * $state can have these values:
  1270.  
  1271. * - DBOF_DEBUGOFF = Turn off debugging
  1272.  
  1273. * - DBOF_DEBUGSCREEN = Turn on debugging on screen (every Query will be dumped on screen)
  1274.  
  1275. * - DBOF_DEBUFILE = Turn on debugging on PHP errorlog
  1276.  
  1277. * You can mix the debug levels by adding the according defines!
  1278.  
  1279. * @param integer $state The DEBUG Level you want to be set
  1280.  
  1281. */
  1282.  
  1283. function SetDebug($state)
  1284.  
  1285. {
  1286.  
  1287. $this->debug = $state;
  1288.  
  1289. }
  1290.  
  1291.  
  1292.  
  1293. /**
  1294.  
  1295. * Returns the current debug setting.
  1296.  
  1297. * @return integer The debug setting (bitmask)
  1298.  
  1299. * @see SetDebug()
  1300.  
  1301. */
  1302.  
  1303. function GetDebug()
  1304.  
  1305. {
  1306.  
  1307. return($this->debug);
  1308.  
  1309. }
  1310.  
  1311.  
  1312.  
  1313. /**
  1314.  
  1315. * Handles output according to internal debug flag.
  1316.  
  1317. * @param string $msg The Text to be included in the debug message.
  1318.  
  1319. * @see error_log
  1320.  
  1321. */
  1322.  
  1323. function PrintDebug($msg)
  1324.  
  1325. {
  1326.  
  1327. if(!$this->debug)
  1328.  
  1329. {
  1330.  
  1331. return;
  1332.  
  1333. }
  1334.  
  1335. if($this->SAPI_type != 'cli')
  1336.  
  1337. {
  1338.  
  1339. $formatstr = "<div align=\"left\" style=\"background-color:#ffffff; color:#000000;\"><pre>DEBUG: %s</pre></div>\n";
  1340.  
  1341. }
  1342.  
  1343. else
  1344.  
  1345. {
  1346.  
  1347. $formatstr = "DEBUG: %s\n";
  1348.  
  1349. }
  1350.  
  1351. if($this->debug & DBOF_DEBUGSCREEN)
  1352.  
  1353. {
  1354.  
  1355. @printf($formatstr,$msg);
  1356.  
  1357. }
  1358.  
  1359. if($this->debug & DBOF_DEBUGFILE)
  1360.  
  1361. {
  1362.  
  1363. @error_log('DEBUG: '.$msg,0);
  1364.  
  1365. }
  1366.  
  1367. }
  1368.  
  1369.  
  1370.  
  1371. /**
  1372.  
  1373. * Returns version of this class.
  1374.  
  1375. * @return string The version of this class.
  1376.  
  1377. */
  1378.  
  1379. function GetClassVersion()
  1380.  
  1381. {
  1382.  
  1383. return($this->classversion);
  1384.  
  1385. }
  1386.  
  1387.  
  1388.  
  1389. /**
  1390.  
  1391. * Returns last used auto_increment id.
  1392.  
  1393. * @param mixed $extsock Optionally an external MySQL socket to use. If not given the internal socket is used.
  1394.  
  1395. * @return integer The last automatic insert id that was assigned by the MySQL server.
  1396.  
  1397. * @see mysql_insert_id
  1398.  
  1399. */
  1400.  
  1401. function LastInsertId($extsock=-1)
  1402.  
  1403. {
  1404.  
  1405. if($extsock==-1)
  1406.  
  1407. {
  1408.  
  1409. return(@mysql_insert_id($this->sock));
  1410.  
  1411. }
  1412.  
  1413. else
  1414.  
  1415. {
  1416.  
  1417. return(@mysql_insert_id($extsock));
  1418.  
  1419. }
  1420.  
  1421. }
  1422.  
  1423.  
  1424.  
  1425. /**
  1426.  
  1427. * Returns count of affected rows by last DML operation.
  1428.  
  1429. * @param mixed $extsock Optionally an external MySQL socket to use. If not given the internal socket is used.
  1430.  
  1431. * @return integer The number of affected rows by previous DML operation.
  1432.  
  1433. * @see mysql_affected_rows
  1434.  
  1435. */
  1436.  
  1437. function AffectedRows($extsock=-1)
  1438.  
  1439. {
  1440.  
  1441. if($extsock==-1)
  1442.  
  1443. {
  1444.  
  1445. return(@mysql_affected_rows($this->sock));
  1446.  
  1447. }
  1448.  
  1449. else
  1450.  
  1451. {
  1452.  
  1453. return(@mysql_affected_rows($extsock));
  1454.  
  1455. }
  1456.  
  1457. }
  1458.  
  1459.  
  1460.  
  1461. /**
  1462.  
  1463. * Converts a MySQL default Datestring (YYYY-MM-DD HH:MI:SS) into a strftime() compatible format.
  1464.  
  1465. * You can use all format tags that strftime() supports, this function simply converts the mysql
  1466.  
  1467. * date string into a timestamp which is then passed to strftime together with your supplied
  1468.  
  1469. * format. The converted datestring is then returned.
  1470.  
  1471. * Please do not use this as default date converter, always use DATE_FORMAT() inside a query
  1472.  
  1473. * whenever possible as this is much faster than using this function! Only if you cannot use
  1474.  
  1475. * the MySQL SQL Date converting functions consider using this function.
  1476.  
  1477. * @param string $mysqldate The MySQL default datestring in format YYYY-MM-DD HH:MI:SS
  1478.  
  1479. * @param string $fmtstring A strftime() compatible format string.
  1480.  
  1481. * @return string The converted date string.
  1482.  
  1483. * @see strftime
  1484.  
  1485. * @see mktime
  1486.  
  1487. */
  1488.  
  1489. function ConvertMySQLDate($mysqldate,$fmtstring)
  1490.  
  1491. {
  1492.  
  1493. $dt = explode(' ',$mysqldate); // Split in date/time
  1494.  
  1495. $dp = explode('-',$dt[0]); // Split date
  1496.  
  1497. $tp = explode(':',$dt[1]); // Split time
  1498.  
  1499. $ts = mktime(intval($tp[0]),intval($tp[1]),intval($tp[2]),intval($dp[1]),intval($dp[2]),intval($dp[0])); // Create time stamp
  1500.  
  1501. if($fmtstring=='')
  1502.  
  1503. {
  1504.  
  1505. $fmtstring = '%c';
  1506.  
  1507. }
  1508.  
  1509. return(strftime($fmtstring,$ts));
  1510.  
  1511. }
  1512.  
  1513.  
  1514.  
  1515. /**
  1516.  
  1517. * Returns microtime in format s.mmmmm.
  1518.  
  1519. * Used to measure SQL execution time.
  1520.  
  1521. * @return float the current time in microseconds.
  1522.  
  1523. */
  1524.  
  1525. function getmicrotime()
  1526.  
  1527. {
  1528.  
  1529. list($usec, $sec) = explode(" ",microtime());
  1530.  
  1531. return ((float)$usec + (float)$sec);
  1532.  
  1533. }
  1534.  
  1535.  
  1536.  
  1537. /**
  1538.  
  1539. * Allows to set the handling of errors.
  1540.  
  1541. *
  1542.  
  1543. * - DBOF_SHOW_NO_ERRORS => Show no security-relevant informations
  1544.  
  1545. * - DBOF_SHOW_ALL_ERRORS => Show all errors (useful for develop)
  1546.  
  1547. * - DBOF_RETURN_ALL_ERRORS => No error/autoexit, just return the mysql_error code.
  1548.  
  1549. * @param integer $val The Error Handling mode you wish to use.
  1550.  
  1551. * @since 0.28
  1552.  
  1553. */
  1554.  
  1555. function setErrorHandling($val)
  1556.  
  1557. {
  1558.  
  1559. $this->showError = $val;
  1560.  
  1561. }
  1562.  
  1563.  
  1564.  
  1565. /**
  1566.  
  1567. * Returns current connection handle.
  1568.  
  1569. * Returns either the internal connection socket or -1 if no active handle exists.
  1570.  
  1571. * Useful if you want to work with mysql* functions in parallel to this class.
  1572.  
  1573. * @return mixed Internal socket value
  1574.  
  1575. * @since 0.32
  1576.  
  1577. */
  1578.  
  1579. function GetConnectionHandle()
  1580.  
  1581. {
  1582.  
  1583. return($this->sock);
  1584.  
  1585. }
  1586.  
  1587.  
  1588.  
  1589. /**
  1590.  
  1591. * Allows to set internal socket to external value.
  1592.  
  1593. * @param mixed New socket handle to set (as returned from mysql_connect())
  1594.  
  1595. * @see mysql_connect
  1596.  
  1597. * @since 0.32
  1598.  
  1599. */
  1600.  
  1601. function SetConnectionHandle($extsock)
  1602.  
  1603. {
  1604.  
  1605. $this->sock = $extsock;
  1606.  
  1607. }
  1608.  
  1609.  
  1610.  
  1611. /**
  1612.  
  1613. * Send error email if programmer has defined a valid email address and
  1614.  
  1615. * enabled it with the define MYSQLDB_SENTMAILONERROR.
  1616.  
  1617. * @param integer $merrno MySQL errno number
  1618.  
  1619. * @param string $merrstr MySQL error description
  1620.  
  1621. * @param string $uerrstr User-supplied error description
  1622.  
  1623. * @see dbdefs.inc.php
  1624.  
  1625. * @see mail
  1626.  
  1627. */
  1628.  
  1629. function SendMailOnError($merrno,$merrstr,$uerrstr)
  1630.  
  1631. {
  1632.  
  1633. if(!defined('MYSQLDB_SENTMAILONERROR') || MYSQLDB_SENTMAILONERROR == 0 || $this->AdminEmail == '')
  1634.  
  1635. {
  1636.  
  1637. return;
  1638.  
  1639. }
  1640.  
  1641. $server = $_SERVER['SERVER_NAME']." (".$_SERVER['SERVER_ADDR'].")";
  1642.  
  1643. if($server == ' ()' || $server == '')
  1644.  
  1645. {
  1646.  
  1647. $server = 'n/a';
  1648.  
  1649. }
  1650.  
  1651. $uagent = $_SERVER['HTTP_USER_AGENT'];
  1652.  
  1653. if($uagent == '')
  1654.  
  1655. {
  1656.  
  1657. $uagent = 'n/a';
  1658.  
  1659. }
  1660.  
  1661. $clientip = $_SERVER['REMOTE_ADDR']." (".@gethostbyaddr($_SERVER['REMOTE_ADDR']).")";
  1662.  
  1663. if($clientip == ' ()' || $clientip == '')
  1664.  
  1665. {
  1666.  
  1667. $clientip = 'n/a';
  1668.  
  1669. }
  1670.  
  1671. $message = "MySQLDB Class v".$this->classversion.": Error occured on ".date('r')." !!!\n\n";
  1672.  
  1673. $message.= " APPLICATION: ".$this->appname."\n";
  1674.  
  1675. $message.= " AFFECTED SERVER: ".$server."\n";
  1676.  
  1677. $message.= " USER AGENT: ".$uagent."\n";
  1678.  
  1679. $message.= " PHP SCRIPT: ".$_SERVER['SCRIPT_FILENAME']."\n";
  1680.  
  1681. $message.= " REMOTE IP ADDR: ".$clientip."\n";
  1682.  
  1683. $message.= " DATABASE DATA: ".$this->user." @ ".$this->host."\n";
  1684.  
  1685. $message.= "SQL ERROR MESSAGE: ".$merrstr."\n";
  1686.  
  1687. $message.= " SQL ERROR CODE: ".$merrno."\n";
  1688.  
  1689. $message.= " QUERY COUNTER: ".$this->querycounter."\n";
  1690.  
  1691. $message.= " INFOTEXT: ".$uerrstr."\n";
  1692.  
  1693. if($this->currentQuery != '')
  1694.  
  1695. {
  1696.  
  1697. $message.= " SQL QUERY:\n";
  1698.  
  1699. $message.= "------------------------------------------------------------------------------------\n";
  1700.  
  1701. $message.= $this->currentQuery."\n";
  1702.  
  1703. }
  1704.  
  1705. $message.= "------------------------------------------------------------------------------------\n";
  1706.  
  1707. if(defined('MYSQLDB_MAIL_EXTRAARGS') && MYSQLDB_MAIL_EXTRAARGS != '')
  1708.  
  1709. {
  1710.  
  1711. @mail($this->AdminEmail,'MySQLDB Class v'.$this->classversion.' ERROR #'.$merrno.' OCCURED!',$message,MYSQLDB_MAIL_EXTRAARGS);
  1712.  
  1713. }
  1714.  
  1715. else
  1716.  
  1717. {
  1718.  
  1719. @mail($this->AdminEmail,'MySQLDB Class v'.$this->classversion.' ERROR #'.$merrno.' OCCURED!',$message);
  1720.  
  1721. }
  1722.  
  1723. }
  1724.  
  1725.  
  1726.  
  1727. /**
  1728.  
  1729. * Retrieve last mysql error number.
  1730.  
  1731. * @param mixed $other_sock Optionally your own connection handle to check, else internal will be used
  1732.  
  1733. * @return integer The MySQL error number of the last operation
  1734.  
  1735. * @see mysql_errno
  1736.  
  1737. * @since 0.33
  1738.  
  1739. */
  1740.  
  1741. function GetErrno($other_sock = -1)
  1742.  
  1743. {
  1744.  
  1745. if( $other_sock == -1 )
  1746.  
  1747. {
  1748.  
  1749. if(!$this->sock)
  1750.  
  1751. {
  1752.  
  1753. return($this->myErrno);
  1754.  
  1755. }
  1756.  
  1757. else
  1758.  
  1759. {
  1760.  
  1761. return(@mysql_errno($this->sock));
  1762.  
  1763. }
  1764.  
  1765. }
  1766.  
  1767. else
  1768.  
  1769. {
  1770.  
  1771. if(!$other_sock)
  1772.  
  1773. {
  1774.  
  1775. return($this->myErrno);
  1776.  
  1777. }
  1778.  
  1779. else
  1780.  
  1781. {
  1782.  
  1783. return(@mysql_errno($other_sock));
  1784.  
  1785. }
  1786.  
  1787. }
  1788.  
  1789. }
  1790.  
  1791.  
  1792.  
  1793. /**
  1794.  
  1795. * Retrieve last mysql error description.
  1796.  
  1797. * @param mixed $other_sock Optionally your own connection handle to check, else internal will be used
  1798.  
  1799. * @return string The MySQL error description of the last operation
  1800.  
  1801. * @see mysql_error
  1802.  
  1803. * @since 0.33
  1804.  
  1805. */
  1806.  
  1807. function GetErrorText($other_sock = -1)
  1808.  
  1809. {
  1810.  
  1811. if( $other_sock == -1 )
  1812.  
  1813. {
  1814.  
  1815. if(!$this->sock)
  1816.  
  1817. {
  1818.  
  1819. return($this->myErrStr);
  1820.  
  1821. }
  1822.  
  1823. else
  1824.  
  1825. {
  1826.  
  1827. return(@mysql_error($this->sock));
  1828.  
  1829. }
  1830.  
  1831. }
  1832.  
  1833. else
  1834.  
  1835. {
  1836.  
  1837. if(!$other_sock)
  1838.  
  1839. {
  1840.  
  1841. return($this->myErrStr);
  1842.  
  1843. }
  1844.  
  1845. else
  1846.  
  1847. {
  1848.  
  1849. return(@mysql_error($other_sock));
  1850.  
  1851. }
  1852.  
  1853. }
  1854.  
  1855. }
  1856.  
  1857.  
  1858.  
  1859. /**
  1860.  
  1861. * Sets connection behavour.
  1862.  
  1863. * If FALSE class uses mysql_connect to connect.
  1864.  
  1865. * If TRUE class uses mysql_pconnect to connect (Persistant connection).
  1866.  
  1867. * @param boolean The new setting for persistant connections.
  1868.  
  1869. * @return boolean The previous state.
  1870.  
  1871. * @since 0.35
  1872.  
  1873. */
  1874.  
  1875. function setPConnect($conntype)
  1876.  
  1877. {
  1878.  
  1879. if(is_bool($conntype)==FALSE)
  1880.  
  1881. {
  1882.  
  1883. return($this->usePConnect);
  1884.  
  1885. }
  1886.  
  1887. $oldtype = $this->usePConnect;
  1888.  
  1889. $this->usePConnect = $conntype;
  1890.  
  1891. return($oldtype);
  1892.  
  1893. }
  1894.  
  1895.  
  1896.  
  1897. /**
  1898.  
  1899. * Escapes a given string with the 'mysql_real_escape_string' method.
  1900.  
  1901. * Always use this function to avoid SQL injections when adding dynamic data to MySQL!
  1902.  
  1903. * This function also handles the settings for magic_quotes_gpc/magic_quotes_sybase, if
  1904.  
  1905. * these settings are enabled this function uses stripslashes() first.
  1906.  
  1907. * @param string $str The string to escape.
  1908.  
  1909. * @return string The escaped string.
  1910.  
  1911. * @since 0.35
  1912.  
  1913. */
  1914.  
  1915. function EscapeString($str)
  1916.  
  1917. {
  1918.  
  1919. $data = $str;
  1920.  
  1921. if(get_magic_quotes_gpc())
  1922.  
  1923. {
  1924.  
  1925. $data = stripslashes($data);
  1926.  
  1927. }
  1928.  
  1929. $link = get_resource_type($this->sock);
  1930.  
  1931. if($this->sock && substr($link,0,5) =='mysql')
  1932.  
  1933. {
  1934.  
  1935. return(mysql_real_escape_string($data,$this->sock));
  1936.  
  1937. }
  1938.  
  1939. else
  1940.  
  1941. {
  1942.  
  1943. return(mysql_escape_string($data));
  1944.  
  1945. }
  1946.  
  1947. }
  1948.  
  1949.  
  1950.  
  1951. /**
  1952.  
  1953. * Method to set the time_names setting of the MySQL Server.
  1954.  
  1955. * Pass it a valid locale string to change the locale setting of MySQL.
  1956.  
  1957. * Note that this is supported only since 5.0.25 of MySQL!
  1958.  
  1959. * @param string $locale A locale string for the language you want to set, i.e. 'de_DE'.
  1960.  
  1961. * @return integer 0 If an error occures or 1 if change was successful.
  1962.  
  1963. * @since 0.36
  1964.  
  1965. */
  1966.  
  1967. function set_TimeNames($locale)
  1968.  
  1969. {
  1970.  
  1971. $rc = $this->Query("SET lc_time_names='".$locale."'",MYSQL_NUM,1);
  1972.  
  1973. if($rc != 1)
  1974.  
  1975. {
  1976.  
  1977. $this->Print_Error('set_TimeNames(): Error while trying to set lc_time_names to "'.$locale.'" !!!');
  1978.  
  1979. return(0);
  1980.  
  1981. }
  1982.  
  1983. $this->locale = $locale;
  1984.  
  1985. return(1);
  1986.  
  1987. }
  1988.  
  1989.  
  1990.  
  1991. /**
  1992.  
  1993. * Method to return the current MySQL setting for the lc_time_names variable.
  1994.  
  1995. * @return string The current setting for the lc_time_names variable.
  1996.  
  1997. * @since 0.36
  1998.  
  1999. */
  2000.  
  2001. function get_TimeNames()
  2002.  
  2003. {
  2004.  
  2005. $data = $this->Query("SELECT @@lc_time_names",MYSQL_NUM,1);
  2006.  
  2007. if(is_array($data)==false)
  2008.  
  2009. {
  2010.  
  2011. $this->Print_Error('get_TimeNames(): Error while trying to retrieve the lc_time_names variable !!!');
  2012.  
  2013. return(0);
  2014.  
  2015. }
  2016.  
  2017. return($data[0]);
  2018.  
  2019. }
  2020.  
  2021.  
  2022.  
  2023. /**
  2024.  
  2025. * Method to set the character set of the current connection.
  2026.  
  2027. * You must specify a valid character set name, else the class will report an error.
  2028.  
  2029. * See http://dev.mysql.com/doc/refman/5.0/en/charset-charsets.html for a list of supported character sets.
  2030.  
  2031. * @param string $charset The charset to set on the MySQL server side.
  2032.  
  2033. * @return integer 1 If all works, else 0 in case of an error.
  2034.  
  2035. * @since 0.36
  2036.  
  2037. */
  2038.  
  2039. function set_CharSet($charset)
  2040.  
  2041. {
  2042.  
  2043. $rc = $this->Query("SET NAMES '".$charset."'",MYSQL_NUM,1);
  2044.  
  2045. if($rc != 1)
  2046.  
  2047. {
  2048.  
  2049. $this->Print_Error('set_Names(): Error while trying to perform SET NAMES "'.$locale.'" !!!');
  2050.  
  2051. return(0);
  2052.  
  2053. }
  2054.  
  2055. $this->character_set = $charset;
  2056.  
  2057. return(1);
  2058.  
  2059. }
  2060.  
  2061.  
  2062.  
  2063. /**
  2064.  
  2065. * Method to return the current MySQL setting for the character_set variables.
  2066.  
  2067. * Note that MySQL returns a list of settings, so this method returns all character_set related
  2068.  
  2069. * settings as an associative array.
  2070.  
  2071. * @return array The current settings for the character_set variables.
  2072.  
  2073. * @since 0.36
  2074.  
  2075. */
  2076.  
  2077. function get_CharSet()
  2078.  
  2079. {
  2080.  
  2081. $retarr = array();
  2082.  
  2083. $stmt = $this->QueryResult("SHOW VARIABLES LIKE 'character_set%'",1);
  2084.  
  2085. while($d = $this->FetchResult($stmt,MYSQL_NUM))
  2086.  
  2087. {
  2088.  
  2089. array_push($retarr,$d);
  2090.  
  2091. }
  2092.  
  2093. $this->FreeResult($stmt);
  2094.  
  2095. return($retarr);
  2096.  
  2097. }
  2098.  
  2099. } // EOF
  2100.  
  2101. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement