BxDolDb.php 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  1. <?php defined('BX_DOL') or defined('BX_DOL_INSTALL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaCore UNA Core
  7. * @{
  8. */
  9. define('BX_DB_MODE_SILENT', PDO::ERRMODE_SILENT);
  10. define('BX_DB_MODE_EXCEPTION', PDO::ERRMODE_EXCEPTION);
  11. define('BX_DB_ERR_CONNECT_FAILD', 1);
  12. define('BX_DB_ERR_QUERY_ERROR', 2);
  13. define('BX_DB_ERR_ESCAPE', 3);
  14. define('BX_PDO_STATE_NOT_EXECUTED', NULL);
  15. define('BX_PDO_STATE_SUCCESS', '00000');
  16. class BxDolDb extends BxDolFactory implements iBxDolSingleton
  17. {
  18. protected static $_rLink;
  19. protected static $_aDbCacheData;
  20. protected static $_aParams;
  21. protected static $_sParamsCacheName = 'sys_options';
  22. protected static $_sParamsCacheNameMixed = 'sys_options_mixed_';
  23. protected static $_sParamsCacheNameMix = 'sys_options_mix_';
  24. protected static $_sErrorKey = 'bx_db_error';
  25. protected static $_aErrors = array(
  26. BX_DB_ERR_CONNECT_FAILD => 'Database connect failed',
  27. BX_DB_ERR_QUERY_ERROR => 'Database query error',
  28. BX_DB_ERR_ESCAPE => 'Escape string error'
  29. );
  30. protected $_bPdoPersistent;
  31. protected $_iPdoFetchType;
  32. protected $_iPdoErrorMode;
  33. protected $_bErrorChecking;
  34. protected $_aError;
  35. protected $_sHost, $_sPort, $_sSocket, $_sDbname, $_sUser, $_sPassword, $_sCharset, $_sStorageEngine;
  36. protected $_oStatement = null;
  37. protected $_oDbCacheObject = null;
  38. /**
  39. * set database parameters and connect to it
  40. */
  41. protected function __construct($aDbConf = false)
  42. {
  43. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  44. trigger_error ('Multiple instances are not allowed for the class: ' . get_class($this), E_USER_ERROR);
  45. parent::__construct();
  46. $this->_bPdoPersistent = true;
  47. $this->_iPdoFetchType = PDO::FETCH_ASSOC;
  48. $this->_iPdoErrorMode = BX_DB_MODE_EXCEPTION;
  49. $this->_bErrorChecking = true;
  50. $this->_aError = array();
  51. $this->_sStorageEngine = 'MYISAM';
  52. if (defined('BX_DATABASE_ENGINE'))
  53. $this->_sStorageEngine = BX_DATABASE_ENGINE;
  54. $this->_sCharset = 'utf8mb4';
  55. if($aDbConf === false) {
  56. $this->_sHost = BX_DATABASE_HOST;
  57. $this->_sPort = BX_DATABASE_PORT;
  58. $this->_sSocket = BX_DATABASE_SOCK;
  59. $this->_sDbname = BX_DATABASE_NAME;
  60. $this->_sUser = BX_DATABASE_USER;
  61. $this->_sPassword = BX_DATABASE_PASS;
  62. }
  63. else {
  64. $this->_sHost = $aDbConf['host'];
  65. $this->_sPort = $aDbConf['port'];
  66. $this->_sSocket = $aDbConf['sock'];
  67. $this->_sDbname = $aDbConf['name'];
  68. $this->_sUser = $aDbConf['user'];
  69. $this->_sPassword = $aDbConf['pwd'];
  70. if(isset($aDbConf['charset']))
  71. $this->_sCharset = $aDbConf['charset'];
  72. if(isset($aDbConf['error_checking']))
  73. $this->_bErrorChecking = $aDbConf['error_checking'];
  74. if(isset($aDbConf['storage_engine']))
  75. $this->_sStorageEngine = $aDbConf['storage_engine'];
  76. }
  77. @set_exception_handler(array($this, 'pdoExceptionHandler'));
  78. }
  79. /**
  80. * Prevent cloning the instance
  81. */
  82. public function __clone()
  83. {
  84. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  85. trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
  86. }
  87. /**
  88. * Get singleton instance of the class
  89. */
  90. public static function getInstance()
  91. {
  92. $null = null;
  93. return self::getInstanceWithConf(false, $null);
  94. }
  95. public static function getInstanceWithConf($aDbConf, &$sError)
  96. {
  97. if(!isset($GLOBALS['bxDolClasses'][__CLASS__])) {
  98. if($aDbConf === false && !defined('BX_DATABASE_HOST'))
  99. return null;
  100. $o = new BxDolDb($aDbConf);
  101. $sErrorMessage = $o->connect();
  102. if($sErrorMessage) {
  103. if($sError !== null)
  104. $sError = $sErrorMessage;
  105. return null;
  106. }
  107. $GLOBALS['bxDolClasses'][__CLASS__] = $o;
  108. }
  109. return $GLOBALS['bxDolClasses'][__CLASS__];
  110. }
  111. public static function getLink()
  112. {
  113. return self::$_rLink;
  114. }
  115. /**
  116. * connect to database with appointed parameters
  117. */
  118. public function connect()
  119. {
  120. if(self::$_rLink)
  121. return;
  122. try {
  123. $sDsn = "mysql:host=" . $this->_sHost . ";";
  124. $sDsn .= $this->_sPort ? "port=" . $this->_sPort . ";" : "";
  125. $sDsn .= $this->_sSocket ? "unix_socket=" . $this->_sSocket . ";" : "";
  126. $sDsn .= "dbname=" . $this->_sDbname . ";charset=" . $this->_sCharset;
  127. self::$_rLink = new PDO($sDsn, $this->_sUser, $this->_sPassword, array(
  128. PDO::ATTR_ERRMODE => $this->_iPdoErrorMode,
  129. PDO::ATTR_DEFAULT_FETCH_MODE => $this->_iPdoFetchType,
  130. PDO::ATTR_PERSISTENT => $this->_bPdoPersistent
  131. ));
  132. $this->pdoExec("SET NAMES 'utf8mb4' COLLATE 'utf8mb4_unicode_ci'");
  133. $this->pdoExec("SET sql_mode = ''");
  134. if (0 == strcasecmp($this->_sStorageEngine, 'INNODB'))
  135. $this->pdoExec("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE");
  136. $sVer = $this->getVersion();
  137. $sStorageEngine = !$sVer || version_compare($sVer, '5.7.5', '>=') ? 'default_storage_engine' : 'storage_engine';
  138. $this->pdoExec("SET $sStorageEngine=" . $this->_sStorageEngine);
  139. $this->cleanMemoryAll();
  140. }
  141. catch (PDOException $oException) {
  142. $oException->errorInfo[self::$_sErrorKey] = array(
  143. 'code' => BX_DB_ERR_CONNECT_FAILD,
  144. 'message' => $oException->getMessage(),
  145. 'trace' => $oException->getTrace()
  146. );
  147. throw $oException;
  148. }
  149. }
  150. /**
  151. * close mysql connection
  152. */
  153. public function disconnect()
  154. {
  155. self::$_rLink = null;
  156. }
  157. /**
  158. * check mysql connection
  159. */
  160. public function ping()
  161. {
  162. try {
  163. $this->pdoQuery("SELECT 1");
  164. }
  165. catch (PDOException $e) {
  166. return false;
  167. }
  168. return true;
  169. }
  170. /**
  171. * Can be used to execute queries which shouldn't return data
  172. */
  173. public function pdoExec($sQuery)
  174. {
  175. return self::$_rLink->exec($sQuery);
  176. }
  177. /**
  178. * Executes query and returns PDOStatement object or false
  179. */
  180. public function pdoQuery($sQuery)
  181. {
  182. return self::$_rLink->query($sQuery);
  183. }
  184. /**
  185. * database query exception handler for exceptions appeared out of the try/catch block
  186. */
  187. public function pdoExceptionHandler($oException)
  188. {
  189. if(!($oException instanceof PDOException)) {
  190. throw $oException;
  191. return;
  192. }
  193. if(!isset($oException->errorInfo[self::$_sErrorKey]))
  194. $oException->errorInfo[self::$_sErrorKey] = array(
  195. 'code' => BX_DB_ERR_QUERY_ERROR,
  196. 'message' => !empty($oException->errorInfo[2]) ? $oException->errorInfo[2] : $oException->getMessage(),
  197. 'trace' => $oException->getTrace()
  198. );
  199. $this->error($oException->errorInfo[self::$_sErrorKey]);
  200. }
  201. /**
  202. * get mysql option
  203. */
  204. function getOption($sName)
  205. {
  206. $oStatement = $this->pdoQuery("SELECT @@{$sName}");
  207. return $this->getOne($oStatement);
  208. }
  209. /**
  210. * execute sql query and return one value result
  211. */
  212. public function getOne($oStatement, $aBindings = array(), $iIndex = 0)
  213. {
  214. if(!$oStatement)
  215. return false;
  216. else if(!($oStatement instanceof PDOStatement) && is_string($oStatement))
  217. $oStatement = $this->prepare($oStatement);
  218. $aResult = array();
  219. if($this->res($oStatement, $aBindings))
  220. $aResult = $oStatement->fetch(PDO::FETCH_NUM);
  221. return is_array($aResult) && count($aResult) ? $aResult[$iIndex] : false;
  222. }
  223. /**
  224. * execute sql query and return one row result
  225. */
  226. function getRow($oStatement, $aBindings = array(), $iFetchType = PDO::FETCH_ASSOC)
  227. {
  228. $aResult = array();
  229. if(!$oStatement)
  230. return $aResult;
  231. else if(!($oStatement instanceof PDOStatement) && is_string($oStatement))
  232. $oStatement = $this->prepare($oStatement);
  233. if(!in_array($iFetchType, array(PDO::FETCH_NUM, PDO::FETCH_ASSOC, PDO::FETCH_BOTH)))
  234. $iFetchType = $this->_iPdoFetchType;
  235. if(!$this->res($oStatement, $aBindings))
  236. return array();
  237. $aResult = $oStatement->fetch($iFetchType);
  238. if($aResult === false)
  239. return array();
  240. return $aResult;
  241. }
  242. /**
  243. * execute sql query and return a column as result
  244. */
  245. function getColumn($oStatement, $aBindings = array(), $iFetchColumnNumber = 0)
  246. {
  247. $aResult = array();
  248. if(!$oStatement)
  249. return $aResult;
  250. else if(!($oStatement instanceof PDOStatement) && is_string($oStatement))
  251. $oStatement = $this->prepare($oStatement);
  252. if(!$this->res($oStatement, $aBindings))
  253. return array();
  254. $aResult = $oStatement->fetchAll(PDO::FETCH_COLUMN, $iFetchColumnNumber);
  255. if($aResult === false)
  256. return array();
  257. return $aResult;
  258. }
  259. /**
  260. * execute sql query and return the first row of result
  261. * and keep $array type and poiter to all data
  262. */
  263. public function getFirstRow($oStatement, $aBindings = array(), $iFetchType = PDO::FETCH_ASSOC)
  264. {
  265. if(!$oStatement)
  266. return array();
  267. else if(!($oStatement instanceof PDOStatement) && is_string($oStatement))
  268. $oStatement = $this->prepare($oStatement);
  269. if(!in_array($iFetchType, array(PDO::FETCH_NUM, PDO::FETCH_ASSOC, PDO::FETCH_BOTH)))
  270. $iFetchType = $this->_iPdoFetchType;
  271. if(!$this->res($oStatement, $aBindings))
  272. return array();
  273. $aResult = $oStatement->fetch($iFetchType);
  274. if($aResult === false)
  275. return array();
  276. $this->_oStatement = $oStatement;
  277. return $aResult;
  278. }
  279. /**
  280. * return next row of pointed last getFirstRow calling data
  281. */
  282. public function getNextRow($iFetchType = PDO::FETCH_ASSOC)
  283. {
  284. if(!$this->_oStatement)
  285. return array();
  286. if(!in_array($iFetchType, array(PDO::FETCH_NUM, PDO::FETCH_ASSOC, PDO::FETCH_BOTH)))
  287. $iFetchType = $this->_iPdoFetchType;
  288. $aResult = $this->_oStatement->fetch($iFetchType);
  289. if($aResult !== false)
  290. return $aResult;
  291. $this->_oStatement = null;
  292. return array();
  293. }
  294. /**
  295. * execute sql query and return table of records as result
  296. */
  297. public function getAll($oStatement, $aBindings = array(), $iFetchType = PDO::FETCH_ASSOC)
  298. {
  299. $aResult = array();
  300. if(!$oStatement)
  301. return $aResult;
  302. else if(!($oStatement instanceof PDOStatement) && is_string($oStatement))
  303. $oStatement = $this->prepare($oStatement);
  304. if(!in_array($iFetchType, array(PDO::FETCH_NUM, PDO::FETCH_ASSOC, PDO::FETCH_BOTH)))
  305. $iFetchType = $this->_iPdoFetchType;
  306. if(!$this->res($oStatement, $aBindings))
  307. return array();
  308. $aResult = $oStatement->fetchAll($iFetchType);
  309. if($aResult === false)
  310. return array();
  311. return $aResult;
  312. }
  313. /**
  314. * Executes sql query and returns table of records as result.
  315. *
  316. * @deprecated use getAll instead.
  317. */
  318. public function fillArray($oStatement, $aBindings = array(), $iFetchType = PDO::FETCH_ASSOC)
  319. {
  320. return $this->getAll($oStatement, $aBindings, $iFetchType);
  321. }
  322. /**
  323. * execute sql query and return table of records as result
  324. */
  325. public function getAllWithKey($oStatement, $sFieldKey, $aBindings = array(), $iFetchType = PDO::FETCH_ASSOC)
  326. {
  327. $aResult = array();
  328. if(!$oStatement)
  329. return $aResult;
  330. else if(!($oStatement instanceof PDOStatement) && is_string($oStatement))
  331. $oStatement = $this->prepare($oStatement);
  332. $aRow = $this->getFirstRow($oStatement, $aBindings, $iFetchType);
  333. while(!empty($aRow)) {
  334. $aResult[$aRow[$sFieldKey]] = $aRow;
  335. $aRow = $this->getNextRow($iFetchType);
  336. }
  337. return $aResult;
  338. }
  339. /**
  340. * execute sql query and return table of records as result
  341. */
  342. public function getPairs($oStatement, $sFieldKey, $sFieldValue, $aBindings = array(), $iFetchType = PDO::FETCH_ASSOC)
  343. {
  344. $aResult = array();
  345. if(!$oStatement)
  346. return $aResult;
  347. else if(!($oStatement instanceof PDOStatement) && is_string($oStatement))
  348. $oStatement = $this->prepare($oStatement);
  349. $aRow = $this->getFirstRow($oStatement, $aBindings, $iFetchType);
  350. while(!empty($aRow)) {
  351. $aResult[$aRow[$sFieldKey]] = $aRow[$sFieldValue];
  352. $aRow = $this->getNextRow($iFetchType);
  353. }
  354. return $aResult;
  355. }
  356. /**
  357. * return number of affected rows in current mysql result
  358. *
  359. * NOTE: PDOStatement::rowCount works for SELECT queries in MySQL.
  360. * So, this method should be rewritten if the other DB engine will be used.
  361. */
  362. public function getNumRows($oStatement = null)
  363. {
  364. if($oStatement && ($oStatement instanceof PDOStatement))
  365. return $oStatement->rowCount();
  366. if($this->_oStatement && ($this->_oStatement instanceof PDOStatement))
  367. return $this->_oStatement->rowCount();
  368. return 0;
  369. }
  370. /**
  371. * returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement.
  372. */
  373. public function getAffectedRows($oStatement = null)
  374. {
  375. return $this->getNumRows($oStatement);
  376. }
  377. public function lastId()
  378. {
  379. return self::$_rLink->lastInsertId();
  380. }
  381. /**
  382. * execute any query return number of rows affected/false
  383. */
  384. public function query($oStatement, $aBindings = array(), $bVerbose = null)
  385. {
  386. if(!$oStatement)
  387. return false;
  388. else if(!($oStatement instanceof PDOStatement) && is_string($oStatement))
  389. $oStatement = $this->prepare($oStatement);
  390. if($this->res($oStatement, $aBindings, $bVerbose))
  391. return $oStatement->rowCount();
  392. return false;
  393. }
  394. /**
  395. * execute any query
  396. */
  397. public function res($oStatement, $aBindings = array(), $bVerbose = null)
  398. {
  399. if(!$oStatement || !($oStatement instanceof PDOStatement))
  400. return false;
  401. if($oStatement->errorCode() == BX_PDO_STATE_SUCCESS)
  402. return true;
  403. if(isset($GLOBALS['bx_profiler']))
  404. $GLOBALS['bx_profiler']->beginQuery($oStatement->queryString);
  405. for ($iAttempts = 3; $iAttempts > 0; --$iAttempts) {
  406. $oException = null;
  407. $iErrorCode = 0;
  408. $bResult = false;
  409. try {
  410. $bResult = $this->executeStatement($oStatement, $aBindings, $bVerbose, $iErrorCode);
  411. } catch (PDOException $oException) {
  412. $iErrorCode = $oException->errorInfo[1];
  413. }
  414. // if deadlock timeout - try again, make sure that deadlock timeout is short
  415. if (!$bResult && (1205 == $iErrorCode || 1213 == $iErrorCode)) {
  416. continue;
  417. }
  418. // if mysql connection is lost - reconnect and try again
  419. if(!$bResult && !$this->ping()) {
  420. $this->disconnect();
  421. $this->connect();
  422. continue;
  423. }
  424. // in all other cases exit from the loop
  425. if ($oException)
  426. throw $oException;
  427. break;
  428. }
  429. if(isset($GLOBALS['bx_profiler']))
  430. $GLOBALS['bx_profiler']->endQuery($oStatement);
  431. //is needed for SILENT mode
  432. if(!$bResult && !empty($this->_aError))
  433. $this->error($this->_aError);
  434. return $bResult;
  435. }
  436. /**
  437. * get mysql server info
  438. */
  439. public function getServerInfo()
  440. {
  441. return self::$_rLink->getAttribute(PDO::ATTR_SERVER_VERSION);
  442. }
  443. /**
  444. * get mysql version
  445. */
  446. public function getVersion()
  447. {
  448. $s = $this->getOne("SELECT VERSION()");
  449. return preg_match("/([0-9\.]+)/", $s, $m) ? $m[1] : false;
  450. }
  451. /**
  452. * get list of tables in database
  453. */
  454. public function listTables()
  455. {
  456. $oStatement = $this->pdoQuery("SHOW TABLES FROM `" . BX_DATABASE_NAME . "`");
  457. return $this->getColumn($oStatement);
  458. }
  459. public function getFields($sTable)
  460. {
  461. $oStatement = $this->pdoQuery("SHOW COLUMNS FROM `" . $sTable . "`");
  462. $aFields = $this->getAll($oStatement);
  463. $aResult = array('original' => array(), 'uppercase' => array());
  464. foreach($aFields as $aField) {
  465. $aResult['original'][] = $aField['Field'];
  466. $aResult['uppercase'][] = strtoupper($aField['Field']);
  467. }
  468. return $aResult;
  469. }
  470. public function fetchField($oStatement, $iField, $aBindings = array())
  471. {
  472. $aResult = array();
  473. if(!$oStatement)
  474. return $aResult;
  475. else if(!($oStatement instanceof PDOStatement) && is_string($oStatement)) {
  476. $oStatement = $this->prepare($oStatement);
  477. if(!$this->res($oStatement, $aBindings))
  478. return $aResult;
  479. }
  480. return $oStatement->getColumnMeta($iField);
  481. }
  482. public function isTableExists($sTable)
  483. {
  484. $aTableNames = $this->listTables();
  485. foreach($aTableNames as $iKey => $sTableName)
  486. $aTableNames[$iKey] = strtoupper($sTableName);
  487. return in_array(strtoupper($sTable), $aTableNames);
  488. }
  489. public function isFieldExists($sTable, $sFieldName)
  490. {
  491. $aFields = $this->getFields($sTable);
  492. return in_array(strtoupper($sFieldName), $aFields['uppercase']);
  493. }
  494. public function isIndexExists($sTable, $sIndexName)
  495. {
  496. $bIndex = false;
  497. $aIndexes = $this->getAll("SHOW INDEXES FROM `" . $sTable . "`");
  498. foreach($aIndexes as $aIndex)
  499. if($aIndex['Key_name'] == $sIndexName) {
  500. $bIndex = true;
  501. break;
  502. }
  503. return $bIndex;
  504. }
  505. public function error($aError)
  506. {
  507. $sErrorType = self::$_aErrors[$aError['code']];
  508. $bVerbose = isset($aError['verbose']) ? (bool)$aError['verbose'] : $this->_bErrorChecking;
  509. if(!$bVerbose) {
  510. $this->log($sErrorType . ': ' . $aError['message']);
  511. if (!defined('BX_DOL_INSTALL')) // this is needed to display error during installation
  512. return;
  513. }
  514. if((defined('BX_DB_FULL_VISUAL_PROCESSING') && BX_DB_FULL_VISUAL_PROCESSING) || defined('BX_DOL_INSTALL')) {
  515. $sOutput = '<div style="border:2px solid red;padding:4px;width:600px;margin:0px auto;">';
  516. $sOutput .= '<div style="text-align:center;background-color:red;color:white;font-weight:bold;">Error</div>';
  517. $sOutput .= '<div style="text-align:center;">' . $sErrorType . '</div>';
  518. if((defined('BX_DB_FULL_DEBUG_MODE') && BX_DB_FULL_DEBUG_MODE) || defined('BX_DOL_INSTALL'))
  519. $sOutput .= $this->errorOutput($aError);
  520. $sOutput .= '</div>';
  521. }
  522. if(defined('BX_DB_DO_EMAIL_ERROR_REPORT') && BX_DB_DO_EMAIL_ERROR_REPORT) {
  523. $sSiteTitle = $this->getParam('site_title');
  524. $sMailBody = "Database error in " . $sSiteTitle . "<br /><br /> \n";
  525. $sMailBody .= $this->errorOutput($aError);
  526. $sMailBody .= "<hr />Auto-report system";
  527. sendMail($this->getParam('site_email'), "Database error in " . $sSiteTitle, $sMailBody, 0, array(), BX_EMAIL_SYSTEM, 'html', true);
  528. }
  529. bx_show_service_unavailable_error_and_exit($sOutput);
  530. }
  531. protected function isParamInCache($sKey)
  532. {
  533. return is_array(self::$_aParams) && isset(self::$_aParams[$sKey]);
  534. }
  535. public function cacheParams($bForceCacheInvalidate = false, $bForceCacheInvalidateMixed = false)
  536. {
  537. if ($bForceCacheInvalidate)
  538. $this->cacheParamsClear();
  539. self::$_aParams = $this->fromCache(self::$_sParamsCacheName, 'getPairs', "SELECT `name`, `value` FROM `sys_options`", "name", "value");
  540. list($sTmplCode, $sTmplName) = BxDolTemplate::retrieveCode();
  541. if(!empty($sTmplCode) && !empty($sTmplName)) {
  542. $iTmplMix = 0;
  543. if(is_array($sTmplCode))
  544. list($sTmplCode, $iTmplMix) = $sTmplCode;
  545. if(empty($iTmplMix))
  546. $iTmplMix = (int)$this->getParam($sTmplName . '_default_mix');
  547. if(!empty($iTmplMix)) {
  548. $sCacheNameMixed = self::$_sParamsCacheNameMixed . $sTmplCode . '_' . $iTmplMix;
  549. if($bForceCacheInvalidateMixed)
  550. $this->cacheParamsClear($sCacheNameMixed);
  551. $aMixed = $this->fromCache($sCacheNameMixed, 'getPairs', "SELECT `option`, `value` FROM `sys_options_mixes2options` WHERE `mix_id`=:mix_id", "option", "value", array(
  552. 'mix_id' => $iTmplMix
  553. ));
  554. if(!empty($aMixed) && is_array($aMixed))
  555. self::$_aParams = array_merge(self::$_aParams, $aMixed);
  556. }
  557. }
  558. if (empty(self::$_aParams)) {
  559. self::$_aParams = array();
  560. return false;
  561. }
  562. return true;
  563. }
  564. public function cacheParamsClear($sCacheName = '')
  565. {
  566. if(empty($sCacheName))
  567. $sCacheName = self::$_sParamsCacheName;
  568. return $this->cleanCache($sCacheName);
  569. }
  570. public function isParam($sKey, $bFromCache = true)
  571. {
  572. if ($bFromCache && $this->isParamInCache($sKey))
  573. return true;
  574. $sQuery = $this->prepare("SELECT `name` FROM `sys_options` WHERE `name` = ? LIMIT 1", $sKey);
  575. return $this->getOne($sQuery) == $sKey;
  576. }
  577. public function addParam($sName, $sValue, $iKateg, $sDesc, $sType)
  578. {
  579. $sQuery = $this->prepare("INSERT INTO `sys_options` SET `category_id` = ?, `name` = ?, `caption` = ?, `value` = ?, `type` = ?", $iKateg, $sName, $sDesc, $sValue, $sType);
  580. $this->query($sQuery);
  581. // renew params cache
  582. $this->cacheParams(true);
  583. }
  584. public function getParam($sKey, $bFromCache = true)
  585. {
  586. if (!$sKey)
  587. return false;
  588. if ($bFromCache && $this->isParamInCache($sKey)) {
  589. return self::$_aParams[$sKey];
  590. } else {
  591. $sQuery = $this->prepare("SELECT `tmo`.`value` AS `value` FROM `sys_options_mixes2options` AS `tmo` INNER JOIN `sys_options_mixes` AS `tm` ON `tmo`.`mix_id`=`tm`.`id` AND `tm`.`active`='1' WHERE `tmo`.`option`=? LIMIT 1", $sKey);
  592. $mixedValue = $this->getOne($sQuery);
  593. if($mixedValue !== false)
  594. return $mixedValue;
  595. $sQuery = $this->prepare("SELECT `value` FROM `sys_options` WHERE `name` = ? LIMIT 1", $sKey);
  596. return $this->getOne($sQuery);
  597. }
  598. }
  599. public function setParam($sKey, $mixedValue, $iMixId = 0)
  600. {
  601. if(empty($iMixId))
  602. $sQuery = $this->prepare("UPDATE `sys_options` SET `value` = ? WHERE `name` = ? LIMIT 1", $mixedValue, $sKey);
  603. else
  604. $sQuery = $this->prepare("REPLACE INTO `sys_options_mixes2options` SET `option` = ?, `mix_id` = ?, `value` = ?", $sKey, $iMixId, $mixedValue);
  605. $bResult = (int)$this->query($sQuery) > 0;
  606. // renew params cache
  607. $bResult &= $this->cacheParams(true, !empty($iMixId));
  608. return $bResult;
  609. }
  610. public function getParamsMix($iId)
  611. {
  612. return $this->fromCache(self::$_sParamsCacheNameMix . $iId, 'getRow', 'SELECT * FROM `sys_options_mixes` WHERE `id`=:id', array(
  613. 'id' => $iId
  614. ));
  615. }
  616. public function getParamsMixActive($sType)
  617. {
  618. return $this->getRow("SELECT * FROM `sys_options_mixes` WHERE `type`=:type AND `active`='1'", array(
  619. 'type' => $sType
  620. ));
  621. }
  622. public function getParamsMixes($sType, $mixedPublished = false)
  623. {
  624. $aBindings = array('type' => $sType);
  625. $sQuery = "SELECT * FROM `sys_options_mixes` WHERE `type`=:type";
  626. if($mixedPublished !== false) {
  627. $aBindings['published'] = (int)$mixedPublished;
  628. $sQuery .= " AND `published`=:published";
  629. }
  630. return $this->getAll($sQuery, $aBindings);
  631. }
  632. public function setTimezone($sTimezone)
  633. {
  634. $oDate = new DateTime('now', new DateTimeZone($sTimezone));
  635. return $this->pdoExec('SET time_zone = "' . $oDate->format('P') . '"') !== false;
  636. }
  637. public function getEncoding()
  638. {
  639. $oStatement = $this->pdoQuery('SELECT @@character_set_database');
  640. if($oStatement !== false)
  641. return $this->getOne($oStatement);
  642. return false;
  643. }
  644. public function setErrorChecking ($b)
  645. {
  646. $this->_bErrorChecking = $b;
  647. }
  648. /**
  649. * Cache functions.
  650. */
  651. public function getDbCacheObject ()
  652. {
  653. if($this->_oDbCacheObject != null)
  654. return $this->_oDbCacheObject;
  655. $sEngine = $this->getParam('sys_db_cache_engine');
  656. $this->_oDbCacheObject = bx_instance('BxDolCache'.$sEngine);
  657. if(!$this->_oDbCacheObject->isAvailable())
  658. $this->_oDbCacheObject = bx_instance('BxDolCacheFile');
  659. return $this->_oDbCacheObject;
  660. }
  661. public function genDbCacheKey ($sName)
  662. {
  663. return 'db_' . $sName . '_' . bx_site_hash() . '.php';
  664. }
  665. public function fromCache ($sName, $sFunc)
  666. {
  667. $aArgs = func_get_args();
  668. array_shift ($aArgs); // shift $sName
  669. array_shift ($aArgs); // shift $sFunc
  670. if (!$this->getParam('sys_db_cache_enable'))
  671. return call_user_func_array (array ($this, $sFunc), $aArgs); // pass other function parameters as database function parameters
  672. $oCache = $this->getDbCacheObject ();
  673. $sKey = $this->genDbCacheKey($sName);
  674. $mixedRet = $oCache->getData($sKey);
  675. if ($mixedRet !== null) {
  676. return $mixedRet;
  677. } else {
  678. $mixedRet = call_user_func_array (array ($this, $sFunc), $aArgs); // pass other function parameters as database function parameters
  679. $oCache->setData($sKey, $mixedRet);
  680. }
  681. return $mixedRet;
  682. }
  683. public function cleanCache ($sName)
  684. {
  685. $oCache = $this->getDbCacheObject();
  686. $sKey = $this->genDbCacheKey($sName);
  687. return $oCache->delData($sKey);
  688. }
  689. public function &fromMemory ($sName, $sFunc)
  690. {
  691. if(array_key_exists($sName, self::$_aDbCacheData) && !defined('BX_DOL_INSTALL') && !defined('BX_DOL_CRON_EXECUTE'))
  692. return self::$_aDbCacheData[$sName];
  693. $aArgs = func_get_args();
  694. array_shift($aArgs); // shift $sName
  695. array_shift($aArgs); // shift $sFunc
  696. self::$_aDbCacheData[$sName] = call_user_func_array (array ($this, $sFunc), $aArgs); // pass other function parameters as database function parameters
  697. return self::$_aDbCacheData[$sName];
  698. }
  699. public function cleanMemory ($sName)
  700. {
  701. if(!isset(self::$_aDbCacheData[$sName]))
  702. return false;
  703. unset(self::$_aDbCacheData[$sName]);
  704. return true;
  705. }
  706. public function cleanMemoryAll ()
  707. {
  708. self::$_aDbCacheData = array();
  709. return true;
  710. }
  711. /**
  712. * It escapes string to pass to mysql query.
  713. * Try to use "prepare" function always (@see BxDolDb::prepare), use "escape" only if "prepare" function is not possible at all.
  714. * Also consider using "implode_escape" function (@see BxDolDb::implode_escape).
  715. *
  716. * @param string $s string to escape
  717. * @return escaped string whcich is ready to pass to SQL query.
  718. */
  719. public function escape($s)
  720. {
  721. try {
  722. $s = self::$_rLink->quote($s);
  723. }
  724. catch (PDOException $oException) {
  725. $oException->errorInfo[self::$_sErrorKey] = array(
  726. 'code' => BX_DB_ERR_ESCAPE,
  727. 'message' => $oException->getMessage(),
  728. 'trace' => $oException->getTrace()
  729. );
  730. throw $oException;
  731. }
  732. return $s;
  733. }
  734. /**
  735. * This function is usefull when you need to form array of parameters to pass to IN(...) SQL construction.
  736. * Example:
  737. * @code
  738. * $a = array(2, 4.5, 'apple', 'car');
  739. * $s = "SELECT * FROM `t` WHERE `a` IN (" . $oDb->implode_escape($a) . ")";
  740. * echo $s; // outputs: SELECT * FROM `t` WHERE `a` IN (2, 4.5, 'apple', 'car')
  741. * @endcode
  742. *
  743. * @param $mixed array or parameters or just one paramter
  744. * @return string which is ready to pass to IN(...) SQL construction
  745. */
  746. public function implode_escape ($mixed)
  747. {
  748. if (is_array($mixed)) {
  749. $s = '';
  750. foreach ($mixed as $v)
  751. $s .= (is_numeric($v) ? $v : $this->escape($v)) . ',';
  752. if ($s)
  753. return substr($s, 0, -1);
  754. else
  755. return 'NULL';
  756. }
  757. return is_numeric($mixed) ? $mixed : ($mixed ? $this->escape($mixed) : 'NULL');
  758. }
  759. /**
  760. * @deprecated
  761. */
  762. public function unescape ($mixed)
  763. {
  764. if(is_array($mixed)) {
  765. foreach($mixed as $k => $v)
  766. $mixed[$k] = $this->getOne("SELECT '$v'");
  767. return $mixed;
  768. }
  769. else
  770. return $this->getOne("SELECT '$mixed'");
  771. }
  772. /**
  773. * Prepare SQL query before execution if some arguments are need to be passed to it.
  774. * All parameters marked with question (?) symbol in SQL query are replaced with parameters passed after SQL query parameter.
  775. * Parameters are properly excaped and surrounded by qutes if needed.
  776. * Example:
  777. * @code
  778. * $sSql = $oDb->prepare("SELECT `a`, `b` from `t` WHERE `c` = ? and `d` = ?", 12, 'aa');
  779. * echo $sSql;// outputs: SELECT `a`, `b` from `t` WHERE `c` = 12 and `d` = 'aa'
  780. * $a = $oDb->getAll($sSql);
  781. * @endcode
  782. *
  783. * @param string $sQuery SQL query, parameters for replacing are marked with ? symbol
  784. * @param mixed $mixed any number if parameters to replace, number of parameters whould match number of ? symbols in SQL query
  785. * @return PDOStatement object with SQL query ready for execution
  786. */
  787. public function prepare($sQuery)
  788. {
  789. if(!self::$_rLink)
  790. return false;
  791. $aArgs = func_get_args();
  792. $sQuery = array_shift($aArgs);
  793. $oStatement = self::$_rLink->prepare($sQuery);
  794. $iIndex = 1;
  795. foreach($aArgs as $mixedArg) {
  796. if(is_null($mixedArg))
  797. $iValueType = PDO::PARAM_NULL;
  798. else if(is_numeric($mixedArg) && is_int($mixedArg))
  799. $iValueType = PDO::PARAM_INT;
  800. else
  801. $iValueType = PDO::PARAM_STR;
  802. $oStatement->bindValue($iIndex++, $mixedArg, $iValueType);
  803. }
  804. return $oStatement;
  805. }
  806. /**
  807. * Prepare SQL query before execution if some arguments are need to be passed to it.
  808. * All parameters marked with question (?) symbol in SQL query are replaced with parameters passed after SQL query parameter.
  809. * Parameters are properly excaped and surrounded by qutes if needed.
  810. * Example:
  811. * @code
  812. * $sSql = $oDb->prepare("SELECT `a`, `b` from `t` WHERE `c` = ? and `d` = ?", 12, 'aa');
  813. * echo $sSql;// outputs: SELECT `a`, `b` from `t` WHERE `c` = 12 and `d` = 'aa'
  814. * $a = $oDb->getAll($sSql);
  815. * @endcode
  816. *
  817. * @param string $sQuery SQL query, parameters for replacing are marked with ? symbol
  818. * @param mixed $mixed any number if parameters to replace, number of parameters whould match number of ? symbols in SQL query
  819. * @return string with SQL query.
  820. */
  821. function prepareAsString($sQuery)
  822. {
  823. $aArgs = func_get_args();
  824. $sQuery = array_shift($aArgs);
  825. $iPos = 0;
  826. foreach ($aArgs as $mixedArg) {
  827. if (is_null($mixedArg))
  828. $s = 'NULL';
  829. elseif (is_numeric($mixedArg))
  830. $s = $mixedArg;
  831. else
  832. $s = $this->escape($mixedArg);
  833. $i = bx_mb_strpos($sQuery, '?', $iPos);
  834. $sQuery = bx_mb_substr_replace($sQuery, $s, $i, 1);
  835. $iPos = $i + get_mb_len($s);
  836. }
  837. return $sQuery;
  838. }
  839. /**
  840. * Convert array of key => values to SQL query.
  841. * Array keys are field names and array values are field values.
  842. * @param $a array
  843. * @param $sDiv fields separator, by default it is ',', another useful value is ' AND '
  844. * @return part of SQL query string
  845. */
  846. public function arrayToSQL($a, $sDiv = ',')
  847. {
  848. $s = '';
  849. foreach($a as $k => $v)
  850. $s .= "`{$k}` = " . $this->escape($v) . $sDiv;
  851. return trim($s, $sDiv);
  852. }
  853. protected function log($s)
  854. {
  855. if (defined('BX_DIRECTORY_PATH_LOGS')) {
  856. $sPath = BX_DIRECTORY_PATH_LOGS;
  857. }
  858. else {
  859. $sDirName = pathinfo(__FILE__, PATHINFO_DIRNAME);
  860. $sPath = $sDirName . '/../../logs/';
  861. }
  862. return file_put_contents($sPath . 'db.err.log', date('Y-m-d H:i:s') . "\t" . $s . "\n", FILE_APPEND);
  863. }
  864. public function executeSQL($sPath, $aReplace = array (), $isBreakOnError = true)
  865. {
  866. if(!file_exists($sPath) || !($rHandler = fopen($sPath, "r")))
  867. return array(array ('query' => "fopen($sPath, 'r')", 'error' => 'file not found or permission denied'));
  868. self::$_rLink->setAttribute(PDO::ATTR_ERRMODE, BX_DB_MODE_SILENT);
  869. $sQuery = "";
  870. $sDelimiter = ';';
  871. $aResult = array();
  872. while(!feof($rHandler)) {
  873. $sStr = trim(fgets($rHandler));
  874. if(empty($sStr) || $sStr[0] == "" || $sStr[0] == "#" || ($sStr[0] == "-" && $sStr[1] == "-"))
  875. continue;
  876. //--- Change delimiter ---//
  877. if(strpos($sStr, "DELIMITER //") !== false || strpos($sStr, "DELIMITER ;") !== false) {
  878. $sDelimiter = trim(str_replace('DELIMITER', '', $sStr));
  879. continue;
  880. }
  881. $sQuery .= $sStr;
  882. //--- Check for multiline query ---//
  883. if(substr($sStr, -strlen($sDelimiter)) != $sDelimiter)
  884. continue;
  885. //--- Execute query ---//
  886. if ($aReplace)
  887. $sQuery = str_replace($aReplace['from'], $aReplace['to'], $sQuery);
  888. if($sDelimiter != ';')
  889. $sQuery = str_replace($sDelimiter, "", $sQuery);
  890. if($this->query(trim($sQuery), array(), false) === false) {
  891. $aResult[] = array('query' => $sQuery, 'error' => $this->_aError['message']);
  892. if ($isBreakOnError)
  893. break;
  894. }
  895. $sQuery = "";
  896. }
  897. fclose($rHandler);
  898. self::$_rLink->setAttribute(PDO::ATTR_ERRMODE, $this->_iPdoErrorMode);
  899. return empty($aResult) ? true : $aResult;
  900. }
  901. protected function executeStatement($oStatement, $aBindings = array(), $bVerbose = null, &$iErrorCode = null)
  902. {
  903. $bResult = false;
  904. if (!isset($aBindings[0])) {
  905. foreach($aBindings as $sKey => $mixedValue) {
  906. if(is_null($mixedValue))
  907. $oStatement->bindValue(":{$sKey}", $mixedValue, PDO::PARAM_NULL);
  908. else if(is_numeric($mixedValue) && is_int($mixedValue))
  909. $oStatement->bindValue(":{$sKey}", $mixedValue, PDO::PARAM_INT);
  910. else
  911. $oStatement->bindValue(":{$sKey}", $mixedValue, PDO::PARAM_STR);
  912. }
  913. $aBindings = array();
  914. }
  915. switch (self::$_rLink->getAttribute(PDO::ATTR_ERRMODE)) {
  916. case PDO::ERRMODE_SILENT:
  917. $bResult = $this->executeStatementSilent($oStatement, $aBindings, $bVerbose);
  918. break;
  919. case PDO::ERRMODE_EXCEPTION:
  920. $bResult = $this->executeStatementException($oStatement, $aBindings, $bVerbose);
  921. break;
  922. }
  923. if (!$bResult && !is_null($iErrorCode)) {
  924. $aError = $oStatement->errorInfo();
  925. $iErrorCode = $aError[1];
  926. }
  927. return $bResult;
  928. }
  929. protected function executeStatementException($oStatement, $aBindings = array(), $bVerbose = null)
  930. {
  931. $bResult = false;
  932. try {
  933. $bResult = $oStatement->execute(!empty($aBindings) && is_array($aBindings) ? $aBindings : null);
  934. }
  935. catch (PDOException $oException) {
  936. $aError = $oStatement->errorInfo();
  937. $oException->errorInfo[self::$_sErrorKey] = array(
  938. 'code' => BX_DB_ERR_QUERY_ERROR,
  939. 'message' => !empty($aError[2]) ? $aError[2] : $oException->getMessage(),
  940. 'query' => $oStatement->queryString,
  941. 'trace' => $oException->getTrace(),
  942. 'verbose' => $bVerbose
  943. );
  944. throw $oException;
  945. }
  946. return $bResult;
  947. }
  948. protected function executeStatementSilent($oStatement, $aBindings = array(), $bVerbose = null)
  949. {
  950. $bResult = $oStatement->execute(!empty($aBindings) && is_array($aBindings) ? $aBindings : null);
  951. if($bResult)
  952. return true;
  953. $aError = $oStatement->errorInfo();
  954. $aTrace = debug_backtrace();
  955. unset($aTrace[0]);
  956. $this->_aError = array(
  957. 'code' => BX_DB_ERR_QUERY_ERROR,
  958. 'message' => !empty($aError[2]) ? $aError[2] : '',
  959. 'query' => $oStatement->queryString,
  960. 'trace' => $aTrace,
  961. 'verbose' => $bVerbose
  962. );
  963. return false;
  964. }
  965. protected function errorOutput($aError)
  966. {
  967. $aErrorLocation = array();
  968. if(!empty($aError['query']) && !empty($aError['trace']))
  969. foreach($aError['trace'] as $aCall )
  970. if(isset($aCall['args']) && is_array($aCall['args']))
  971. foreach($aCall['args'] as $argNum => $argVal)
  972. if((is_string($argVal) && strcmp($argVal, $aError['query']) == 0) || ($argVal instanceof PDOStatement && strcmp($argVal->queryString, $aError['query']) == 0)) {
  973. $aErrorLocation['file'] = isset($aCall['file']) ? $aCall['file'] : (isset($aCall['class']) ? 'class: ' . $aCall['class'] : 'undefined');
  974. $aErrorLocation['line'] = isset($aCall['line']) ? $aCall['line'] : 'undefined';
  975. $aErrorLocation['function'] = $aCall['function'];
  976. $aErrorLocation['arg'] = $argNum;
  977. }
  978. $sOutput = '';
  979. if(!empty($aError['query']))
  980. $sOutput .= '<p><b>Query:</b><br />' . $aError['query'] . '</p>';
  981. if(!empty($aError['message']))
  982. $sOutput .= '<p><b>Mysql error:</b><br />' . $aError['message'] . '</p>';
  983. if(!empty($aErrorLocation))
  984. $sOutput .= '<p><b>Location:</b><br />The error was found in <b>' . $aErrorLocation['function'] . '</b> function in the file <b>' . $aErrorLocation['file'] . '</b> at line <b>' . $aErrorLocation['line'] . '</b>.</p>';
  985. $sOutput .= '<p><b>collation_connection:</b><br />' . $this->getOne("SELECT @@collation_connection") . '</p>';
  986. if(!empty($aError['trace'])) {
  987. $sBackTrace = print_r($aError['trace'], true);
  988. if (defined ('BX_DATABASE_USER'))
  989. $sBackTrace = str_replace('[_sUser:protected] => ' . BX_DATABASE_USER, '[_sUser:protected] => *****', $sBackTrace);
  990. if (defined ('BX_DATABASE_PASS'))
  991. $sBackTrace = str_replace('[_sPassword:protected] => ' . BX_DATABASE_PASS, '[_sPassword:protected] => *****', $sBackTrace);
  992. $sOutput .= '<div><b>Debug backtrace:</b></div><div style="overflow:scroll;height:300px;border:1px solid gray;"><pre>' . htmlspecialchars_adv($sBackTrace) . '</pre></div>';
  993. }
  994. if(!empty(self::$_aParams)) {
  995. $sSettings = var_export(self::$_aParams, true);
  996. $sOutput .= '<div><b>Settings:</b></div><div style="overflow:scroll;height:300px;border:1px solid gray;"><pre>' . htmlspecialchars_adv($sSettings) . '</pre></div>';
  997. }
  998. $sOutput .= '<p><b>Called script:</b><br />' . $_SERVER['PHP_SELF'] . '</p>';
  999. if(!empty($_REQUEST)) {
  1000. $sRequest = var_export($_REQUEST, true);
  1001. $sOutput .= '<p><b>Request parameters:</b><br /><pre>' . htmlspecialchars_adv($sRequest) . '</pre></p>';
  1002. }
  1003. return $sOutput;
  1004. }
  1005. }
  1006. /**
  1007. * Create the very first instance and initiate connetion to database.
  1008. */
  1009. BxDolDb::getInstance();
  1010. function getParam($sParamName, $bUseCache = true)
  1011. {
  1012. return BxDolDb::getInstance()->getParam($sParamName, $bUseCache);
  1013. }
  1014. function setParam($sParamName, $sParamVal)
  1015. {
  1016. return BxDolDb::getInstance()->setParam($sParamName, $sParamVal);
  1017. }
  1018. /** @} */