/** * 构造函数 * @param type $tableName * @param type $full 如果为真将为全表名 */ public function __construct($table = null, $full = null, $driver = null) { $this->tableName = $this->get_table($table, $full); //初始化默认表 $this->db = dbFactory::factory($driver, $this->tableName); //获得数据库引擎 }
public static function getCurrentMonthSalesByDate() { $date = date('Y-m-d'); $sql = "SELECT SUM(amount) as TotalSales,date FROM `payment` WHERE YEAR(date)=YEAR('{$date}') AND MONTH(date)=MONTH('{$date}') GROUP BY date"; $report_result = dbFactory::getFactory($sql)->select_data(); return $report_result; }
public static function userAuthentication($username, $password) { $sql = "SELECT * FROM users WHERE username='******' AND password='******'"; $user_data = dbFactory::getFactory($sql)->select_data(); if (count($user_data) > 0) { $_SESSION['username'] = $user_data[0]['username']; $_SESSION['first_name'] = $user_data[0]['first_name']; $_SESSION['last_name'] = $user_data[0]['last_name']; $_SESSION['title'] = $user_data[0]['title']; $_SESSION['password'] = $user_data[0]['password']; $_SESSION['profile_pic'] = $user_data[0]['profile_pic']; $user_id = $user_data[0]["user_id"]; $sql = "SELECT user_group_id FROM user_has_groups WHERE user_id='{$user_id}'"; $user_group_result = dbFactory::getFactory($sql)->select_data(); $user_groups = array(); foreach ($user_group_result as $groups) { array_push($user_groups, $groups["user_group_id"]); } $_SESSION["user_groups"] = $user_groups; return true; } else { session_destroy(); return false; } }
public static function userAuthentication($username, $password, $user_group_id) { // $sql ="SELECT * FROM users WHERE username='******' AND password='******'"; $sql = "SELECT U.*,UG.user_group_id FROM users AS U LEFT OUTER JOIN user_has_groups AS UG ON\r\nU.user_id=UG.user_id RIGHT OUTER JOIN user_groups AS G ON \r\nUG.user_group_id=G.user_group_id\r\nWHERE U.username='******' AND U.password='******' UG.user_group_id='{$user_group_id}'"; $user_data = dbFactory::getFactory($sql)->select_data(); if (count($user_data) > 0) { $_SESSION['username'] = $user_data[0]['username']; $_SESSION['first_name'] = $user_data[0]['first_name']; $_SESSION['last_name'] = $user_data[0]['last_name']; $_SESSION['title'] = $user_data[0]['title']; $_SESSION['password'] = $user_data[0]['password']; $_SESSION['profile_pic'] = $user_data[0]['profile_pic']; // $user_id = $user_data[0]["user_id"]; // $sql = "SELECT user_group_id FROM user_has_groups WHERE user_id='$user_id'"; // $user_group_result = dbFactory::getFactory($sql)->select_data(); // $user_groups = Array(); // foreach($user_group_result as $groups) // { // array_push($user_groups, $groups["user_group_id"]); // } // $_SESSION["user_groups"]=$user_groups; return true; } else { session_destroy(); return false; } }
/** * 返回工厂实例,单例模式 */ public static function factory($driver = null, $tableName = null) { //只实例化一个对象 if (is_null(self::$dbFactory)) { self::$dbFactory = new dbFactory(); } if (is_null($driver)) { $driver = C("DB_DRIVER"); } if (is_null($tableName)) { $tableName = 'empty'; } if (isset(self::$dbFactory->driver_list[$tableName])) { return self::$dbFactory->driver_list[$tableName]; } self::$dbFactory->getDriver($driver, $tableName); return self::$dbFactory->driver_list[$tableName]; }
/** * @expectedException DbNotFoundException */ public function testInvalidType() { $type = 'unknow'; $obj = dbFactory::getDb($type, '0.0.0.0', '0', 'asdfg', 'root', 'rrr'); }
public static function getLast3Notifications() { $sql = "SELECT * FROM notifications ORDER BY notification_id DESC LIMIT 0,3"; $results = dbFactory::getFactory($sql)->select_data(); return $results; }