/** * import a sql script into the given profile. * * The name of the script should be store in install/sql/$name.databasetype.sql * in the directory of the component. (replace databasetype by mysql, pgsql etc.) * * @param string $name the name of the script, without suffixes */ public function execSQLScript($name, $profile = '') { $tools = jDb::getTools($profile); $p = jDb::getProfile($profile); $driver = $p['driver']; if ($driver == 'pdo') { preg_match('/^(\\w+)\\:.*$/', $p['dsn'], $m); $driver = $m[1]; } $tools->execSQLScript($this->path . 'install/sql/' . $name . '.' . $driver . '.sql'); }
/** * return the profile name used for jacl connection * @return string profile name */ public static function getProfile() { static $profile = ''; if ($profile == '') { try { $prof = jDb::getProfile('jacl_profile', true); } catch (Exception $e) { $prof = jDb::getProfile(); } $profile = $prof['name']; } return $profile; }
function __construct($sel, $driver, $isprofile = true) { if ($isprofile) { $p = jDb::getProfile($driver); if ($p['driver'] == 'pdo') { $this->driver = substr($p['dsn'], 0, strpos($p['dsn'], ':')); } else { $this->driver = $p['driver']; } } else { $this->driver = $driver; } $this->_compiler = 'jDaoCompiler'; $this->_compilerPath = JELIX_LIB_PATH . 'dao/jDaoCompiler.class.php'; parent::__construct($sel); }
/** * Size of the database * @return array the total size and record of the database */ public static function dbSize() { $profile = jDb::getProfile(); $con = jDb::getConnection(); $totalRecords = $totalSize = 0; if ($profile['driver'] == 'mysql' or $profile['driver'] == 'mysqli') { $results = $con->query('SHOW TABLE STATUS FROM `' . $profile['database'] . '`'); foreach ($results as $status) { $totalRecords += $status->Rows; $totalSize += $status->Data_length + $status->Index_length; } $totalSize = $totalSize / 1024; if ($totalSize > 1024) { $totalSize = round($totalSize / 1024, 2) . ' MB'; } else { $totalSize = round($totalSize, 2) . ' KB'; } } return array($totalRecords, $totalSize); }