Example #1
0
		public static function StartApp()
		{
			ob_start('ob_gzhandler');
			session_start();
			
			// Defines
			define('BASEURL', substr((empty($_SERVER['HTTPS']) ? 'http://' : 'https://' ) . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'],0,-10));
			define('BASEPATH', substr($_SERVER['SCRIPT_FILENAME'],0,-10));
			
			// Helper Boot Loader
			require(BASEPATH.'/core/bootloader.php');
			
			// Initialize Helpers
			BootLoader::loadHelpers();
			Registry::getInstance();
			
			// Handle Errors
			Registry::setDebugMode(true);
			set_error_handler('Template::handleError');
			set_exception_handler('Template::handleException');
	
			// Initialize Database
			Model::$db = DBO::getInstance('sqlite:example.sqldb');
			
			// Init Autoloads
			spl_autoload_register('Autoload::controllers');
			spl_autoload_register('Autoload::models');
			
			// Determine Controllers and Methods
			Routes::getRoute();
			
			// Run Application
			Routes::run();
		}
Example #2
0
 /**
  * 构造函数
  *
  */
 function __construct()
 {
     // 获取数据库操作对象
     if (self::$db == null) {
         self::$db = base::get_instance()->db;
     }
     $this->cache =& $GLOBALS['memcached'];
 }
 protected static function nuevaDb()
 {
     include_once SYS_PATH . 'DataBase.php';
     if (!isset(Model::$db)) {
         Model::$db = new DataBase();
     }
     return Model::$db;
 }
Example #4
0
 public function __construct($data = null, $rawData = false)
 {
     self::$services = ServiceContainer::getInstance();
     self::$db = self::$services->get('db');
     $this->initialize();
     if ($data) {
         $rawData ? $this->setRawData($data) : $this->setData($data);
     }
 }
Example #5
0
 /**
  * Set a PDO connection to be reused
  */
 private static function setDataSourse()
 {
     try {
         $datasoursename = DBConfig::TYPE . ':host=' . DBConfig::HOST . ';dbname=' . DBConfig::NAME;
         $options = array(PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ, PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING);
         self::$db = new PDO($datasoursename, DBConfig::USER, DBConfig::PASS, $options);
     } catch (PDOException $e) {
         exit('Database connection could not be established.');
     }
 }
 /**
  * Creates a PDO connection to MySQL
  *
  * @return boolean  Returns TRUE on success (dies on failure)
  */
 public function __construct()
 {
     $dsn = 'mysql:dbname=' . DB_NAME . ';host=' . DB_HOST;
     try {
         self::$db = new PDO($dsn, DB_USER, DB_PASS);
     } catch (PDOExeption $e) {
         die("Couldn't connect to the database.");
     }
     return TRUE;
 }
 /**
  * Creates a PDO connection to your datebase.
  *
  * @return boolean
  */
 public function _construct()
 {
     $dsn = 'mysql:dbname' . DB_NAME . ';host=' . DB_HOST;
     try {
         self::$db = new PDO($dsn, DB_USER, DB_PASS);
     } catch (PDOException $e) {
         $echoError = new Error($e);
         exit;
     }
     return TRUE;
 }
Example #8
0
 /**
  * Renvoie un objet de connexion à la BD en initialisant la connexion au besoin
  * 
  * @return PDO L'objet PDO de connexion à la BDD
  */
 private static function getBd()
 {
     if (self::$db == null) {
         // Récupération des paramètres de configuration BD
         $connection = Configuration::get("connection");
         $login = Configuration::get("login");
         $password = Configuration::get("password");
         // Création de la connexion
         self::$db = new PDO($connection, $login, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
     }
     return self::$db;
 }
Example #9
0
 /**
  * This function is used to create a connexion to the database with PDO
  * @return PDO Object
  */
 private function getDb()
 {
     if (self::$db === null) {
         //recovery of configuration parameters to connect to the database
         $dsn = Configuration::get("dsn");
         $login = Configuration::get("login");
         $password = Configuration::get("password");
         //Creation of the connexion
         self::$db = new PDO($dsn, $login, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
     }
     return self::$db;
 }
Example #10
0
 public static function getInstance()
 {
     if (!isset(self::$db)) {
         try {
             self::$db = new \PDO('mysql:host=' . 'localhost' . ';dbname=' . 'teste', 'root', '1234');
             self::$db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
             self::$db->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_OBJ);
         } catch (PDOException $e) {
             die("Erro na Conexão: " . $e->getMessage());
         }
     }
     return self::$db;
 }
Example #11
0
 static function init()
 {
     Model::db();
     Model::check_login();
     foreach (glob(APP_PATH . SL . 'actionHelpers/*.php') as $file) {
         /** @noinspection PhpIncludeInspection */
         include_once $file;
     }
     global $titlePage;
     global $config;
     $titlePage = $config['settings']['title'];
     Route::launch();
 }
Example #12
0
 public function __construct(array $_data = array())
 {
     if (!isset(self::$db)) {
         self::$db = Core::getDb();
     }
     if (!isset(self::$request)) {
         self::$request = Core::$request;
     }
     if (!isset(self::$profile)) {
         self::$profile = Auth::$profile;
         self::$uid = self::$profile->user_id;
     }
     if (isset($_data)) {
         $this->_data = $_data;
     }
 }
Example #13
0
 /**
  *构造函数
  *
  *完成数据库的链接
  */
 public function __construct()
 {
     //打开数据库
     $dns = 'mysql:host=' . DB_HOST . ';port=' . DB_PORT . ';dbname=' . DB_NAME;
     try {
         if (!isset(self::$db)) {
             //实例化PDO
             self::$db = new PDO($dns, DB_USER, DB_PASS);
             //开启异常处理模式
             self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
             //设置字符集
             self::$db->query('set names ' . DB_CHARSET);
         }
     } catch (PDOException $e) {
         die('无法打开数据库');
     }
 }
Example #14
0
 /**
  * 自动初始化
  * @param string $name  表名
  * @param string $prefix 前缀
  * @param string $connect 连接数据库的类型
  * @param string $alias 別名
  * @author wave
  */
 public function __construct($name = null, $prefix = null, $connect = null, $alias = null)
 {
     $this->_initialize();
     $this->prefix = $prefix;
     $this->name = $this->prefix . $name;
     $this->alias = $alias;
     $this->connect = $connect;
     if (empty(self::$db)) {
         //防止多次加載
         load('config.php', APP_PATH . DS . DATABASE);
         //数据库配置文件
         load('db.class.php', ROOT_PATH);
         //加载连接数据库类
         if (!empty($this->connect)) {
             self::$db = !empty($this->connect) ? self::link($this->connect) : 1;
             //进行初始化数据
         } else {
             self::$db = isset(config::$default) ? self::link(config::$default) : 1;
         }
     }
 }
Example #15
0
 public static function connect($server = "development")
 {
     $dbYaml = DB::getParse();
     self::$db = DB::connect($dbYaml[$server]['host'], $dbYaml[$server]['username'], $dbYaml[$server]['password'], $dbYaml[$server]['database']);
 }
Example #16
0
 /**
  * Close the connection
  *
  * @return void
  * @author Justin Palmer
  **/
 public function __destruct()
 {
     self::$db = null;
 }
Example #17
0
 /**
  * 获取回复消息
  */
 public function get_msg($info)
 {
     $key = $info['keyword'];
     switch ($info['keyword']) {
         case 'subscribe':
             //$sign = M("Msg")->where("keyword='{$info['keyword']}'")->find();
             $sign = M("Msg")->where("`keyword` REGEXP '^{$key}\$|{$key},|,{$key},|,{$key}\$'")->find();
             self::subscribe_handler($info);
             break;
         case 'unsubscribe':
             self::unsubscribe_handler($info);
             break;
         default:
             //判断刮刮卡
             $sign = self::card($info);
             if (!is_null($sign)) {
                 return $sign;
             }
             //判断大转盘
             $sign = self::turn($info);
             if (!is_null($sign)) {
                 return $sign;
             }
             //微调研
             $sign = self::survey($info);
             if (!is_null($sign)) {
                 return $sign;
             }
             //优惠券
             $sign = self::coupon($info);
             if (!is_null($sign)) {
                 return $sign;
             }
             $wish = $this->config['wish'];
             $idx = strpos($info['keyword'], $wish);
             if ($this->config['wish_status'] == 1 && strpos($info['keyword'], $wish) === 0) {
                 //后台设置的许愿关键字开头
                 $user = self::getUser($info['from']);
                 $addData = array('name' => $user['nickname'], 'webid' => $info['from'], 'msg' => substr($info['keyword'], $idx + strlen($wish)), 'addtime' => date('Y-m-d H:i:s'), 'add' => time(), 'flag' => 0);
                 D("Receive")->add($addData);
                 $dsn = "mysql://" . $this->config['db_user'] . ":" . $this->config['db_password'] . "@" . $this->config['db_host'] . ":3306/" . $this->config['db_name'];
                 C('DB_PREFIX', '');
                 $db = new Model("Receive");
                 $rst = $db->db(1, $dsn)->add($addData);
                 return array('type' => 1, 'reply' => $this->config['wishContent']);
             }
             $article_type = D("ArticleType")->where(array('name' => $info['keyword']))->find();
             if ($article_type) {
                 $list = D("Article")->where(array('pid' => $article_type['id'], 'status' => 1, 'is_show' => 1))->limit(8)->order('id desc')->select();
                 $items = array();
                 foreach ($list as $val) {
                     $items[] = array('title' => $val['title'], 'img' => $val['cover'], 'desc' => cutstr($val['content'], 30), 'url' => DOMAIN . __ROOT__ . '/index.php/Mobile/Article/detail.html?id=' . $val['id']);
                 }
                 $sign = array('type' => 2, 'reply' => serialize($items));
                 return $sign;
             }
             //关键字回复
             //TODO::多关键字匹配
             // $sign = M("Msg")->where("keyword='{$info['keyword']}'")->find();
             $sign = M("Msg")->where("`keyword` REGEXP '^{$key}\$|^{$key},|,{$key},|,{$key}\$'")->find();
             break;
     }
     if (is_null($sign)) {
         $sign = M("Msg")->where("keyword='default'")->find();
     }
     return $sign;
 }
 /**
  * Model Constructor
  * @param mixed $id
  **/
 public function __construct($id = '')
 {
     self::$db = static::$db;
     if ($id != '') {
         if (is_array($id)) {
             self::$_id = $id;
         } else {
             self::$_id['id'] = $id;
         }
         $this->add = FALSE;
     }
     $this->is_instance = TRUE;
 }
Example #19
0
 public static function setDb(PDO $db)
 {
     self::$db = $db;
 }
Example #20
0
 function anonym_model()
 {
     $model = new Model("users");
     $users = $model->db()->select("select name, email, id from users where age > ? ;", [30]);
     //print_r($users);
 }
Example #21
0
 protected static function db()
 {
     if (self::$db == NULL) {
         self::$db = new MySQLi(DB_HOST, DB_USER, DB_PASS, DB_DATABASE);
     }
     return self::$db;
 }
Example #22
0
 /**
  * Get the instance of Database object and connect.
  * @return connection to the database.
  */
 public static function getDatabase()
 {
     self::$db = Core::getInstance("Database")->getConnection();
     return Core::getInstance("Database")->getConnection();
 }