Overview

Packages

  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Datatype
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Functions

  • addAutoIncrementToTables
  • addSalts
  • alterTableHandling
  • checkMySQLDatabaseCreation
  • checkMySQLDatabaseExists
  • checkMySQLDatabaseUse
  • checkMySQLDropDatabase
  • checkMySQLDropTable
  • checkMySQLLockTable
  • checkMySQLTableCreation
  • checkMySQLUnlockTables
  • convertToDatetime
  • doMySQLConnect
  • doMySQLSelectDB
  • fetchMySQLCharsets
  • fetchMySQLStorageEngines
  • fetchMySQLUser
  • fetchMySQLVersion
  • getMySQLDatabaseExtension
  • getSetupMySQLDBConnection
  • hasMySQLExtension
  • hasMySQLiExtension
  • injectSQL
  • removeComments
  • removeRemarks
  • splitSqlFile
  • urlDecodeTable
  • urlDecodeTables
  • Overview
  • Package
  • Function
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * This file contains various helper functions to read specific values needed for setup checks.
  4:  *
  5:  * @package    Setup
  6:  * @subpackage Helper_MySQL
  7:  * @version    SVN Revision $Rev:$
  8:  *
  9:  * @author     Unknown
 10:  * @copyright  four for business AG <www.4fb.de>
 11:  * @license    http://www.contenido.org/license/LIZENZ.txt
 12:  * @link       http://www.4fb.de
 13:  * @link       http://www.contenido.org
 14:  */
 15: 
 16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 17: 
 18: function hasMySQLExtension() {
 19:     return (isPHPExtensionLoaded("mysql") == CON_EXTENSION_AVAILABLE) ? true : false;
 20: }
 21: 
 22: function hasMySQLiExtension() {
 23:     return (isPHPExtensionLoaded("mysqli") == CON_EXTENSION_AVAILABLE) ? true : false;
 24: }
 25: 
 26: function doMySQLConnect($host, $username, $password) {
 27:     $aOptions = array(
 28:         'connection' => array(
 29:             'host' => $host,
 30:             'user' => $username,
 31:             'password' => $password
 32:         )
 33:     );
 34:     try {
 35:         $db = new cDb($aOptions);
 36:     } catch (Exception $e) {
 37:         return array($db, false);
 38:     }
 39: 
 40:     if ($db->connect() == 0) {
 41:         return array($db, false);
 42:     } else {
 43:         return array($db, true);
 44:     }
 45: }
 46: 
 47: /**
 48:  * Selects a desired database by the link identifier and database name
 49:  * @param resource $linkid  MySQLi/MySQL link identifier
 50:  * @param string $database
 51:  * @return boolean
 52:  */
 53: function doMySQLSelectDB($linkid, $database) {
 54:     $extension = getMySQLDatabaseExtension();
 55: 
 56:     if (CON_SETUP_MYSQLI === $extension) {
 57:         return (@mysqli_select_db($linkid, $database)) ? true : false;
 58:     } elseif (CON_SETUP_MYSQL === $extension) {
 59:         return (@mysql_select_db($database, $linkid)) ? true : false;
 60:     } else {
 61:         return false;
 62:     }
 63: }
 64: 
 65: function getSetupMySQLDBConnection($full = true) {
 66:     global $cfg;
 67: 
 68:     $cfgDb = $cfg['db'];
 69: 
 70:     if ($full === false) {
 71:         // Connection parameter without database
 72:         unset($cfgDb['connection']['database']);
 73:     }
 74: 
 75:     $db = new cDb($cfgDb);
 76:     return $db;
 77: }
 78: 
 79: /**
 80:  * Checks existing MySQL extensions and returns 'mysqli' as default, 'mysql' or null.
 81:  * @return string|null
 82:  */
 83: function getMySQLDatabaseExtension() {
 84:     if (hasMySQLiExtension()) {
 85:         return CON_SETUP_MYSQLI;
 86:     } elseif (hasMySQLExtension()) {
 87:         return CON_SETUP_MYSQL;
 88:     } else {
 89:         return null;
 90:     }
 91: }
 92: 
 93: function fetchMySQLVersion($db) {
 94:     $db->query("SELECT VERSION()");
 95: 
 96:     return ($db->nextRecord()) ? $db->f(0) : false;
 97: }
 98: 
 99: function fetchMySQLUser($db) {
100:     $db->query("SELECT USER()");
101: 
102:     return ($db->nextRecord()) ? $db->f(0) : false;
103: }
104: 
105: function checkMySQLDatabaseCreation($db, $database) {
106:     if (checkMySQLDatabaseExists($db, $database)) {
107:         return true;
108:     } else {
109:         $db->query("CREATE DATABASE `%s`", $database);
110:         return ($db->getErrorNumber() == 0) ? true : false;
111:     }
112: }
113: 
114: function checkMySQLDatabaseExists($db, $database) {
115:     $db->connect();
116: 
117:     if (doMySQLSelectDB($db->getLinkId(), $database)) {
118:         return true;
119:     } else {
120:         $db->query("SHOW DATABASES LIKE '%s'", $database);
121:         return ($db->nextRecord()) ? true : false;
122:     }
123: }
124: 
125: function checkMySQLDatabaseUse($db, $database) {
126:     $db->connect();
127:     return doMySQLSelectDB($db->getLinkId(), $database);
128: }
129: 
130: function checkMySQLTableCreation($db, $database, $table) {
131:     if (checkMySQLDatabaseUse($db, $database) == false) {
132:         return false;
133:     }
134: 
135:     $db->query("CREATE TABLE `%s` (test INT(1) NOT NULL) ENGINE = MYISAM;", $table);
136: 
137:     return ($db->getErrorNumber() == 0) ? true : false;
138: }
139: 
140: function checkMySQLLockTable($db, $database, $table) {
141:     if (checkMySQLDatabaseUse($db, $database) == false) {
142:         return false;
143:     }
144: 
145:     $db->query("LOCK TABLES `%s` WRITE", $table);
146: 
147:     return ($db->getErrorNumber() == 0) ? true : false;
148: }
149: 
150: function checkMySQLUnlockTables($db, $database) {
151:     if (checkMySQLDatabaseUse($db, $database) == false) {
152:         return false;
153:     }
154: 
155:     $db->query("UNLOCK TABLES");
156: 
157:     return ($db->getErrorNumber() == 0) ? true : false;
158: }
159: 
160: function checkMySQLDropTable($db, $database, $table) {
161:     if (checkMySQLDatabaseUse($db, $database) == false) {
162:         return false;
163:     }
164: 
165:     $db->query("DROP TABLE `%s`", $table);
166: 
167:     return ($db->getErrorNumber() == 0) ? true : false;
168: }
169: 
170: function checkMySQLDropDatabase($db, $database) {
171:     $db->query("DROP DATABASE `%s`", $database);
172: 
173:     return ($db->getErrorNumber() == 0) ? true : false;
174: }
175: 
176: function fetchMySQLStorageEngines($db) {
177:     $db->query("SHOW ENGINES");
178: 
179:     $engines = array();
180: 
181:     while ($db->nextRecord()) {
182:         $engines[] = $db->f(0);
183:     }
184: 
185:     return $engines;
186: }
187: 
188: /**
189:  * Returns all suppported character sets (field Charset) from the MySQL database.
190:  * @param cDB|null  $db
191:  * @return array
192:  */
193: function fetchMySQLCharsets($db = null) {
194:     if (!is_object($db)) {
195:         // No DB object, return static list
196:         return array(
197:             'big5', 'dec8', 'cp850', 'hp8', 'koi8r', 'latin1', 'latin2', 'swe7', 'ascii', 'ujis',
198:             'sjis', 'hebrew', 'tis620', 'euckr', 'koi8u', 'gb2312', 'greek', 'cp1250', 'gbk',
199:             'latin5', 'armscii8', 'utf8', 'ucs2', 'cp866', 'keybcs2', 'macce', 'macroman', 'cp852',
200:             'latin7', 'utf8mb4', 'cp1251', 'utf16', 'cp1256', 'cp1257', 'utf32', 'binary', 'geostd8',
201:             'cp932', 'eucjpms',
202:         );
203:     }
204: 
205:     $db->query('SHOW CHARACTER SET');
206: 
207:     $charsets = array();
208: 
209:     while ($db->nextRecord()) {
210:         $charsets[] = $db->f('Charset');
211:     }
212: 
213:     return $charsets;
214: }
215: 
216: ?>
CMS CONTENIDO 4.9.2 API documentation generated by ApiGen 2.8.0