2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 08/29/2004 *
4 * =================== Last change: 08/29/2004 *
6 * -------------------------------------------------------------------- *
7 * File : lib-mysql3.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Database layer for MySQL 3/4/5 server *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Datenbankschicht fuer MySQL 3/4/5 Server *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2012 by Mailer Developer Team *
20 * For more information visit: http://mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
44 function SQL_QUERY ($sqlString, $F, $L, $enableCodes = true) {
46 if (!isset($GLOBALS[__FUNCTION__][$sqlString])) {
47 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called: ' . $sqlString);
50 $sqlStringModified = trim($sqlString);
52 // Empty query string or link is not up?
53 if (empty($sqlStringModified)) {
55 reportBug(__FUNCTION__, __LINE__, sprintf("SQL string is empty, please fix this: file=%s, line=%s",
59 } elseif (!SQL_IS_LINK_UP()) {
60 // We should not quietly ignore this
61 reportBug(__FUNCTION__, __LINE__, sprintf("Cannot query database: sqlString=%s,file=%s,line=%s",
68 // Remove \t, \n and \r from queries they may confuse some MySQL versions
69 $sqlStringModified = str_replace(array(chr(9), chr(10), chr(13)), array(' ', ' ', ' '), $sqlStringModified);
71 // Compile config entries out
72 $sqlStringModified = SQL_PREPARE_SQL_STRING($sqlStringModified, $enableCodes);
74 // Cache it and remember as last SQL query
75 $GLOBALS[__FUNCTION__][$sqlString] = $sqlStringModified;
76 $GLOBALS['last_sql'] = $sqlStringModified;
77 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Stored cache: ' . $sqlStringModified);
79 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cache used: ' . $sqlString);
81 // Use cache (to save a lot function calls
82 $GLOBALS['last_sql'] = $GLOBALS[__FUNCTION__][$sqlString];
84 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cache is: ' . $sqlString);
88 $querytimeBefore = microtime(true);
91 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'F=' . basename($F) . ',L=' . $L . ',sql=' . $GLOBALS['last_sql']);
92 $result = mysql_query($GLOBALS['last_sql'], SQL_GET_LINK())
93 or SQL_ERROR($F, $L, 'file='. basename($F) . ',line=' . $L . ':mysql_error()=' . mysql_error() . ',last_query=' . $GLOBALS['last_sql']);
94 //* DEBUG: */ logDebugMessage($F, $L, 'sql=' . $GLOBALS['last_sql'] . ',affected=' . SQL_AFFECTEDROWS() . ',numRows='.(is_resource($result) ? SQL_NUMROWS($result) : gettype($result)));
96 // Calculate query time
97 $queryTime = microtime(true) - $querytimeBefore;
99 // Add this query to array including timing
100 addSqlToDebug($result, $GLOBALS['last_sql'], $queryTime, $F, $L);
102 // Save last successfull query
103 setConfigEntry('db_last_query', $GLOBALS['last_sql']);
105 // Count all query times
106 incrementConfigEntry('sql_time', $queryTime);
109 incrementConfigEntry('sql_count');
112 if (SQL_DEBUG_ENABLED()) {
113 // Is this the first call?
114 if (!isset($GLOBALS['sql_first_entry'])) {
116 appendLineToFile(getCachePath() . 'mysql.log', 'Module=' . getModule());
117 $GLOBALS['sql_first_entry'] = true;
121 appendLineToFile(getCachePath() . 'mysql.log', basename($F) . '|LINE=' . $L . '|NUM=' . (is_resource($result) ? SQL_NUMROWS($result) : 'false') . '|AFFECTED=' . SQL_AFFECTEDROWS() . '|QUERYTIME:' . $queryTime . '): ' . str_replace(array(chr(13), chr(10)), array('', ' '), $GLOBALS['last_sql']));
124 // Increment stats entry
125 incrementStatsEntry('db_hits');
132 function SQL_NUMROWS ($resource) {
133 // Valid link resource?
134 if (!SQL_IS_LINK_UP()) return false;
136 // Link is not up, no rows by default
139 // Is the result a valid resource?
140 if (isset($GLOBALS['sql_numrows'][intval($resource)])) {
142 $lines = $GLOBALS['sql_numrows'][intval($resource)];
143 } elseif (is_resource($resource)) {
144 // Get the count of rows from database
145 $lines = mysql_num_rows($resource);
147 // Remember it in cache
148 $GLOBALS['sql_numrows'][intval($resource)] = $lines;
150 // No resource given, please fix this
151 reportBug(__FUNCTION__, __LINE__, 'No resource given! result[]=' . gettype($resource) . ',last_sql=' . $GLOBALS['last_sql']);
159 function SQL_AFFECTEDROWS() {
160 // Valid link resource?
161 if (!SQL_IS_LINK_UP()) return false;
164 $lines = mysql_affected_rows(SQL_GET_LINK());
171 function SQL_FETCHROW ($resource) {
172 // Is a result resource set?
173 if ((!is_resource($resource)) || (!SQL_IS_LINK_UP())) return false;
175 // Fetch the data and return it
176 return mysql_fetch_row($resource);
180 function SQL_FETCHARRAY ($res) {
181 // Is a result resource set?
182 if ((!is_resource($res)) || (!SQL_IS_LINK_UP())) return false;
184 // Load row from database
185 $row = mysql_fetch_assoc($res);
187 // Return only arrays here
188 if (is_array($row)) {
192 // Return a false, else some loops would go endless...
198 function SQL_RESULT ($resource, $row, $field = '0') {
199 // Is $resource valid?
200 if ((!is_resource($resource)) || (!SQL_IS_LINK_UP())) return false;
202 // Run the result command
203 $result = mysql_result($resource, $row, $field);
205 // ... and return the result
210 function SQL_CONNECT ($host, $login, $password, $F, $L) {
212 $linkResource = mysql_connect($host, $login, $password) or SQL_ERROR($F, $L, mysql_error());
214 // Set the link resource
215 if (is_resource($linkResource)) {
217 * A non-resource (boolean) may happen on installation phase which
218 * shall not be set here. Only valid link resources shall be set so
219 * SQL_IS_LINK_UP() will only return 'true' if there is really a
220 * working database link.
222 SQL_SET_LINK($linkResource);
225 // Return the resource
226 return $linkResource;
229 // SQL select database
230 function SQL_SELECT_DB ($dbName, $F, $L) {
231 // Is there still a valid link? If not, skip it.
232 if (!SQL_IS_LINK_UP()) return false;
235 return mysql_select_db($dbName, SQL_GET_LINK()) or SQL_ERROR($F, $L, mysql_error());
239 function SQL_CLOSE ($F, $L) {
240 if (!SQL_IS_LINK_UP()) {
245 // Close database link and forget the link
246 $close = mysql_close(SQL_GET_LINK()) or SQL_ERROR($F, $L, mysql_error());
256 function SQL_FREERESULT ($resource) {
257 if ((!is_resource($resource)) || (!SQL_IS_LINK_UP())) {
263 $res = mysql_free_result($resource);
265 // And return that result of freeing it...
269 // SQL string escaping
270 function SQL_QUERY_ESC ($sqlString, $data, $F, $L, $run = true, $strip = true, $secure = true) {
272 if ((!SQL_IS_LINK_UP()) || (!is_array($data))) {
273 // Link is down or data is not an array
274 /* DEBUG: */ logDebugMessage($F, $L, 'SQL_IS_LINK_UP()=' . intval(SQL_IS_LINK_UP()) . ',data[]=' . gettype($data) . ',sqlString=' . $sqlString . ': ABORTING!');
278 // Init array for escaped data with SQL string
279 $dataSecured = array(
280 '__sql_string' => $sqlString
284 foreach ($data as $key => $value) {
285 $dataSecured[$key] = SQL_ESCAPE($value, $secure, $strip);
289 $query = call_user_func_array('sprintf', $dataSecured);
292 // Run SQL query (default)
293 return SQL_QUERY($query, $F, $L);
295 // Return secured string
300 // Get id from last INSERT command
301 function SQL_INSERTID () {
302 if (!SQL_IS_LINK_UP()) return false;
303 return mysql_insert_id();
306 // Escape a string for the database
307 function SQL_ESCAPE ($str, $secureString = true, $strip = true) {
309 if (!isset($GLOBALS['sql_escapes'][''.$str.''])) {
310 // Prepare the string here
311 $str = SQL_PREPARE_SQL_STRING($str);
313 // Secure string first? (which is the default behaviour!)
314 if ($secureString === true) {
316 $str = secureString($str, $strip);
319 if (!SQL_IS_LINK_UP()) {
320 // Fall-back to escapeQuotes() when there is no link
321 $ret = escapeQuotes($str);
322 } elseif (function_exists('mysql_real_escape_string')) {
323 // The new and improved version
324 $ret = mysql_real_escape_string($str, SQL_GET_LINK());
325 } elseif (function_exists('mysql_escape_string')) {
326 // The obsolete function
327 $ret = mysql_escape_string($str, SQL_GET_LINK());
329 // If nothing else works, fall back to escapeQuotes() again
330 $ret = escapeQuotes($str);
334 $GLOBALS['sql_escapes'][''.$str.''] = $ret;
338 return $GLOBALS['sql_escapes'][''.$str.''];
341 // SELECT query string from table, columns and so on... ;-)
342 function SQL_RESULT_FROM_ARRAY ($table, $columns, $idRow, $id, $F, $L) {
343 // Is columns an array?
344 if (!is_array($columns)) {
346 reportBug(__FUNCTION__, __LINE__, sprintf("columns is not an array. %s != array, file=%s, line=%s",
352 // Abort here with 'false'
356 // Is this is a simple array?
357 if ((is_array($columns[0])) && (isset($columns[0]['column']))) {
358 // Begin with SQL query
361 // No, it comes from XML, so get it back from it
362 $sql .= getSqlPartFromXmlArray($columns);
365 $sql .= " FROM `{?_MYSQL_PREFIX?}_%s` WHERE `%s`='%s' LIMIT 1";
367 // Yes, prepare the SQL statement
368 $sql = 'SELECT `' . implode('`,`', $columns) . "` FROM `{?_MYSQL_PREFIX?}_%s` WHERE `%s`='%s' LIMIT 1";
372 return SQL_QUERY_ESC($sql,
381 // ALTER TABLE wrapper function
382 function SQL_ALTER_TABLE ($sql, $F, $L, $enableCodes = true) {
383 // Abort if link is down
384 if (!SQL_IS_LINK_UP()) return false;
386 // This is the default result...
389 // Determine index/fulltext/unique word
392 isInString('INDEX', $sql)
394 isInString('KEY', $sql)
396 isInString('FULLTEXT', $sql)
398 isInString('UNIQUE', $sql)
402 // Extract table name
403 $tableArray = explode(' ', $sql);
404 $tableName = str_replace('`', '', $tableArray[2]);
407 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'sql=' . $sql . ',tableName=' . $tableName . ',tableArray=<pre>' . print_r($tableArray, true) . '</pre>,isAlterIndex=' . intval($isAlterIndex));
409 // Shall we add/drop?
410 if (((isInString('ADD', $sql)) || (isInString('DROP', $sql)) || (isInString('CHANGE', $sql))) && ($isAlterIndex === false)) {
411 // Try two columns, one should fix
412 foreach (array(4,5) as $idx) {
413 // If an entry is not set, abort here
414 if (!isset($tableArray[$idx])) {
416 logDebugMessage(__FUNCTION__, __LINE__, 'columnName=' . $columnName . ',idx=' . $idx . ',sql=' . $sql . ' is missing!');
420 // And column name as well
421 $columnName = $tableArray[$idx];
424 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'columnName=' . $columnName . ',idx=' . $idx . ',sql=' . $sql . ',hasZeroNums=' . intval(ifSqlColumnExists($tableName, $columnName)));
426 // Do we have no entry on ADD or an entry on DROP/CHANGE?
427 if (((!ifSqlColumnExists($tableName, $columnName)) && (isInString('ADD', $sql))) || ((ifSqlColumnExists($tableName, $columnName)) && ((isInString('DROP', $sql)) || ((isInString('CHANGE', $sql)) && ($idx == 4) && ((!ifSqlColumnExists($tableName, $tableArray[5])) || ($columnName == $tableArray[5])))))) {
429 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Executing: ' . $sql);
430 $result = SQL_QUERY($sql, $F, $L, false);
432 // Skip further attempt(s)
434 } elseif ((((ifSqlColumnExists($tableName, $columnName)) && (isInString('ADD', $sql))) || ((!ifSqlColumnExists($tableName, $columnName)) && ((isInString('DROP', $sql))) || (isInString('CHANGE', $sql)))) && ($columnName != 'KEY')) {
435 // Abort here because it is alreay there
436 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Skipped: sql=' . $sql . ',columnName=' . $columnName . ',idx=' . $idx);
438 } elseif ((!ifSqlColumnExists($tableName, $columnName)) && (isInString('DROP', $sql))) {
439 // Abort here because we tried to drop a column which is not there (never created maybe)
440 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'No drop: ' . $sql);
442 } elseif ($columnName != 'KEY') {
443 // Something didn't fit, we better log it
444 logDebugMessage(__FUNCTION__, __LINE__, 'Possible problem: ' . $sql . ',hasZeroNums=' . intval(ifSqlColumnExists($tableName, $columnName)) . '');
447 } elseif ((getTableType() == 'InnoDB') && (isInString('FULLTEXT', $sql))) {
448 // Skip this query silently because InnoDB does not understand fulltext indexes
449 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("Skipped FULLTEXT: sql=%s,tableName=%s,hasZeroNums=%d,file=%s,line=%s", $sql, $tableName, intval((is_bool($result)) ? 0 : ifSqlColumnExists($columnName)), $F, $L));
450 } elseif ($isAlterIndex === true) {
451 // And column name as well without backticks
452 $keyName = str_replace('`', '', $tableArray[5]);
453 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyName=' . $keyName . ',tableArray=<pre>' . print_r($tableArray, true) . '</pre>');
455 // Is this "UNIQUE" or so? FULLTEXT has been handled the elseif() block above
456 if (in_array(strtoupper($tableArray[4]), array('INDEX', 'UNIQUE', 'KEY', 'FULLTEXT'))) {
460 while (isInString(',', $keyName)) {
462 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyName=' . $keyName . 'begin=' . $begin . ' - BEFORE');
463 $keyName = str_replace('`', '', $tableArray[count($tableArray) - $begin]);
464 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyName=' . $keyName . 'begin=' . $begin . ' - BETWEEN');
467 $keyName = str_replace(array('(', ')'), array('', ''), $keyName);
468 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'keyName=' . $keyName . 'begin=' . $begin . ' - AFTER');
476 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'tableName=' . $tableName . ', tableArray[3]=' . $tableArray[3] . ',keyName=' . $keyName);
477 if (($tableArray[3] == 'ADD') && (!isSqlTableIndexFound($tableName, $keyName))) {
478 // Send it to the SQL_QUERY() function to add it
479 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'sql=' . $sql . ' - ADDING!');
480 $result = SQL_QUERY($sql, $F, $L, $enableCodes);
481 } elseif (($tableArray[3] == 'DROP') && (isSqlTableIndexFound($tableName, $keyName))) {
482 // Send it to the SQL_QUERY() function to drop it
483 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'sql=' . $sql . ' - DROPPING!');
484 $result = SQL_QUERY($sql, $F, $L, $enableCodes);
487 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Not executed: ' . $sql);
490 // Other ALTER TABLE query
491 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $sql);
492 $result = SQL_QUERY($sql, $F, $L, $enableCodes);
499 // Getter for SQL link
500 function SQL_GET_LINK () {
504 // Is it in the globals?
505 if (isset($GLOBALS['sql_link'])) {
507 $link = $GLOBALS['sql_link'];
515 function SQL_SET_LINK ($link) {
516 // Is this a resource or null?
517 if ((ifFatalErrorsDetected()) && (isInstallationPhase())) {
518 // This may happen in installation phase
520 } elseif ((!is_resource($link)) && (!is_null($link))) {
521 // This should never happen!
522 reportBug(__FUNCTION__, __LINE__, sprintf("Type of link is not resource or null, type=%s", gettype($link)));
526 $GLOBALS['sql_link'] = $link;
529 $GLOBALS['is_sql_link_up'] = is_resource($link);
532 // Checks if the link is up
533 function SQL_IS_LINK_UP () {
534 // Do we have cached this?
535 if (!isset($GLOBALS['is_sql_link_up'])) {
537 $GLOBALS['is_sql_link_up'] = is_resource(SQL_GET_LINK());
541 return $GLOBALS['is_sql_link_up'];
544 // Wrapper function to make code more readable
545 function SQL_HASZERONUMS ($result) {
546 // Just pass it through
547 return (SQL_NUMROWS($result) === 0);
550 // Wrapper function to make code more readable
551 function SQL_HASZEROAFFECTED () {
552 // Just pass it through
553 return (SQL_AFFECTEDROWS() === 0);
556 // Private function to prepare the SQL query string
557 function SQL_PREPARE_SQL_STRING ($sqlString, $enableCodes = true) {
558 // Is it already cached?
559 if (!isset($GLOBALS['sql_strings'][$sqlString])) {
560 // Compile URI codes+config+expression code
561 $sqlString2 = FILTER_COMPILE_EXPRESSION_CODE(FILTER_COMPILE_CONFIG(compileUriCode($sqlString)));
563 // Do final compilation
564 $GLOBALS['sql_strings'][$sqlString] = doFinalCompilation($sqlString2, false, $enableCodes);
568 return $GLOBALS['sql_strings'][$sqlString];
571 // Creates a MySQL TIMESTAMP compatible string from given Uni* timestamp
572 function SQL_EPOCHE_TO_TIMESTAMP ($timestamp) {
573 return generateDateTime($timestamp, 7);
576 // Log SQL errors to debug.log in installation phase or call reportBug()
577 function SQL_ERROR ($file, $line, $message) {
578 // Remember plain error in last_sql_error
579 $GLOBALS['last_sql_error'] = mysql_error();
581 // Do we have installation phase?
582 if (isInstallationPhase()) {
584 * In installation phase, we don't want SQL errors abort e.g. connection
585 * tests, so just log it away.
587 logDebugMessage($file, $line, $message);
589 // Regular mode, then call reportBug()
590 reportBug($file, $line, $message);
594 // Check if there is a SQL table created
595 function ifSqlTableExists ($tableName) {
596 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'tableName=' . $tableName . ' - ENTERED!');
598 if (!isset($GLOBALS[__FUNCTION__][$tableName])) {
599 // Check if the table is there
600 $result = SQL_QUERY_ESC("SHOW TABLES FROM `{?__DB_NAME?}` WHERE `Tables_in_{?__DB_NAME?}`='{?_MYSQL_PREFIX?}_%s'",
601 array($tableName), __FILE__, __LINE__);
603 // Is there an entry?
604 $GLOBALS[__FUNCTION__][$tableName] = (SQL_NUMROWS($result) == 1);
605 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'tableName=' . $tableName . ',numRows=' . intval($GLOBALS[__FUNCTION__][$tableName]));
609 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'tableName=' . $tableName . ',result=' . intval($GLOBALS[__FUNCTION__][$tableName]) . ' - EXIT!');
610 return $GLOBALS[__FUNCTION__][$tableName];
613 // Is a table column there?
614 function ifSqlColumnExists ($tableName, $columnName) {
615 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'tableName=' . $tableName . ',columnName=' . $columnName . ' - ENTERED!');
617 if (!isset($GLOBALS[__FUNCTION__][$tableName][$columnName])) {
618 // And column name as well
619 $columnName = str_replace('`', '', $columnName);
621 // Get column information
622 $result = SQL_QUERY_ESC("SHOW COLUMNS FROM `%s` LIKE '%s'",
626 ), __FUNCTION__, __LINE__);
629 $GLOBALS[__FUNCTION__][$tableName][$columnName] = (!SQL_HASZERONUMS($result));
630 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'tableName=' . $tableName . ',columnName=' . $columnName . ',hasZeroNums=' . intval(SQL_HASZERONUMS($result)) . ',numRows=' . intval($GLOBALS[__FUNCTION__][$tableName][$columnName]));
633 SQL_FREERESULT($result);
637 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'tableName=' . $tableName . ',columnName=' . $columnName . ',result=' . intval($GLOBALS[__FUNCTION__][$tableName][$columnName]) . ' - EXIT!');
638 return $GLOBALS[__FUNCTION__][$tableName][$columnName];
641 // Checks depending on the mode if the index is there
642 function isSqlTableIndexFound ($tableName, $keyName) {
643 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'tableName=' . $tableName . ',columnName=' . $keyName . ' - ENTERED!');
645 if (!isset($GLOBALS[__FUNCTION__][$tableName][$keyName])) {
647 $result = SQL_QUERY_ESC("SHOW INDEX FROM `%s`", array($tableName), __FUNCTION__, __LINE__);
649 // The column is not found by default
650 $GLOBALS[__FUNCTION__][$tableName][$keyName] = false;
653 while ($content = SQL_FETCHARRAY($result)) {
654 // Add all entries for better caching behavior
655 $GLOBALS[__FUNCTION__][$tableName][$content['Key_name']] = true;
659 SQL_FREERESULT($result);
662 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'tableName=' . $tableName . ',columnName=' . $keyName . ',result=' . intval($GLOBALS[__FUNCTION__][$tableName][$keyName]) . ' - CACHE!');
666 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'tableName=' . $tableName . ',columnName=' . $keyName . ',result=' . intval($GLOBALS[__FUNCTION__][$tableName][$keyName]) . ' - EXIT!');
667 return $GLOBALS[__FUNCTION__][$tableName][$keyName];
670 // Init database layer
671 function initDatabaseLayer () {
672 // Set all required variables:
673 $GLOBALS['last_sql_error'] = '';
676 // Get last SQL error
677 function getLastSqlError () {
678 return $GLOBALS['last_sql_error'];
681 // Gets an array (or false if none is found) from all supported engines
682 function getArrayFromSupportedSqlEngines ($support = 'YES') {
686 // This also worked, now we need to check if the selected database type is supported
687 $result = SQL_QUERY('SHOW ENGINES', __FUNCTION__, __LINE__);
689 // Do we have entries? (Bad if not)
690 if (SQL_NUMROWS($result) > 0) {
691 // Load all and check for active entries
692 while ($content = SQL_FETCHARRAY($result)) {
693 // Is this supported?
694 if (($support == 'ALL') || ($content['Support'] == $support)) {
696 array_push($engines, $content);
697 } elseif (isDebugModeEnabled()) {
698 // Log it away in debug mode
699 logDebugMessage(__FUNCTION__, __LINE__, 'Engine ' . $content['Engine'] . ' is not supported (' . $content['Supported'] . ')');
708 SQL_FREERESULT($result);