public function __construct($settings) { $this->_settings = $settings; switch ($this->_settings['db_library']) { case 'mysql': $factory = new MySQLFactory(); break; case 'mysqli': $factory = new MySQLiFactory(); break; } $this->_bd_driver = $factory->createInstance(); }
private static function checkMySqlConfig() { if (!MySQLiFactory::configIsReadable()) { require_once 'SetupProcessor.php'; $processor = new SetupProcessor(); $tmpl = new Template(); $tmpl->setTemplate('html.tpl'); $content = $processor->processParams($_GET, $_POST); $tmpl->assign('content', $content); echo $tmpl->render(); exit; } }
private static function createInstance() { if (!self::configIsReadable()) { die('MySQL configuration file is not readable.' . "\n"); } include self::$CONFIG_FILE; try { self::$INSTANCE = new mysqli($host, $user, $passwd); } catch (Exception $ex) { die('Sorry, could not connect to database.'); } if (!self::$INSTANCE->select_db($dbname)) { self::createDatabase($dbname); } }
public function testGetInstance() { $instance = MySQLiFactory::getInstance(); $this->assertNotNull($instance); }
private function logDownload() { $retval = false; $db = MySQLiFactory::create(); if (!$db->connect_error) { $logExists = $this->existsInLogs(); if (!$logExists) { $query = 'INSERT INTO `download_stats` (`url`, `name`, `count`) VALUES (?, ?, ?)'; } else { $query = 'UPDATE `download_stats` SET `count` = `count` + 1 WHERE `url` = ?'; } if ($stmt = $db->prepare($query)) { $url = $this->getUrl(); $name = $this->getName(); $count = 1; if ($logExists) { $stmt->bind_param('s', $url); } else { $stmt->bind_param('ssi', $url, $name, $count); } $stmt->execute(); $stmt->close(); unset($stmt); $retval = true; } $db->close(); } unset($db); return $retval; }