Exemplo n.º 1
0
 /**
  * 
  * @throws Exception
  */
 public static function connect()
 {
     // TODO apply custom config
     //$databaseConfig = Core\Config::databaseConfig;
     //$datebaseConfig['hostname']; etc
     $conn = new \mysqli("sfsuswe.com", "s15g03", "LFLWJ3aqeZXCHfje", "student_s15g03");
     if ($conn->connect_errno) {
         throw new Exception("MySQL connection failure: " . $conn->connect_error);
     } else {
         self::$connection = $conn;
     }
 }
Exemplo n.º 2
0
 public function findAll($opciones = array(), $pagina = 1, $items_by_page = 20)
 {
     $db = CoreDb::getInstance();
     $where = "";
     // select all active users
     if (sizeof($opciones) > 0) {
         $w = CoreRoute::getWhere($opciones);
         if (sizeof($w) > 0) {
             $where = " WHERE " . implode(" AND ", $w);
         }
     }
     $result = $db->query("SELECT count(id) as total FROM " . $this->dbTable . $where, 1);
     $total = $result[0]["total"];
     $result = $db->query("SELECT * FROM " . $this->dbTable . $where . " LIMIT " . ($pagina - 1) * $items_by_page . "," . $items_by_page);
     return array("records" => $result, "total" => $total);
 }
Exemplo n.º 3
0
 /**
  * 取得数据库类实例
  * @static
  * @access public
  * @param mixed $config 连接配置
  * @return Object 返回数据库驱动类
  */
 public static function getInstance($config = array())
 {
     $md5 = md5(serialize($config));
     if (!isset(self::$instance[$md5])) {
         // 解析连接参数 支持数组和字符串
         $options = self::parseConfig($config);
         // 兼容mysqli
         if ('mysqli' == $options['type']) {
             $options['type'] = 'mysql';
         }
         // 如果采用lite方式 仅支持原生SQL 包括query和execute方法
         $class = !empty($options['lite']) ? 'Core\\db\\Lite' : 'Core\\db\\driver\\' . ucwords(strtolower($options['type']));
         if (class_exists($class)) {
             self::$instance[$md5] = new $class($options);
         } else {
             // 类没有定义
             //TODO E(L('_NO_DB_DRIVER_').': ' . $class);
         }
     }
     self::$_instance = self::$instance[$md5];
     return self::$_instance;
 }
Exemplo n.º 4
0
 private function __construct($host, $user, $password, $dbname, $type, $dbConnectType = 'pdo')
 {
     if (!extension_loaded($dbConnectType)) {
         header('Content-Type:text/html; charset=utf-8');
         die('没有' . $dbConnectType . '数据库扩展!');
     }
     self::$dbConnectType = $dbConnectType;
     //不同数据库类型连接
     switch ($dbConnectType) {
         case 'mysql':
             $db = new Db\MySQL();
             break;
         case 'mysqli':
             $db = new Db\MySQLi();
             break;
         case 'pdo':
             $db = new Db\PDO();
             break;
         default:
             $db = new Db\MySQLi();
     }
     self::$db[$type] = $db->connect($host, $user, $password, $dbname);
 }
Exemplo n.º 5
0
 public function __construct()
 {
     if (self::$_object === null) {
         self::$_object = \Phpfox_Database::instance();
     }
 }
Exemplo n.º 6
0
 public static function getDbInstance()
 {
     return CoreDb::getInstance();
 }
Exemplo n.º 7
0
 private static function db()
 {
     $coreDb = new CoreDb(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME);
     try {
         $coreDb->connect();
     } catch (Exception $e) {
     }
 }
Exemplo n.º 8
0
 /**
  * Method to set a prefix
  *
  * @param string $prefix     Contains a tableprefix
  *
  * @return CoreDb
  */
 public function setPrefix($prefix = '')
 {
     self::$prefix = $prefix;
     return $this;
 }