Exemplo n.º 1
0
 public function exec($assoc = false)
 {
     //echo $this->_sql; die();
     try {
         $this->_pdo->exec('SET NAMES utf8');
         switch ($this->_sql) {
             case stripos($this->_sql, 'select'):
                 if (count($this->bindVal) > 0) {
                     $result = $this->bind("select", $assoc);
                 } else {
                     $q = $this->_pdo->query($this->_sql);
                     !$assoc ? $result = $q->fetchall() : ($result = $q->fetchall(PDO::FETCH_ASSOC));
                 }
                 break;
             case stripos($this->_sql, 'delete'):
                 $this->_pdo->exec($this->_sql) ? $result = 1 : ($result = 0);
                 break;
             case stripos($this->_sql, 'insert'):
                 if (count($this->bindVal) > 0) {
                     $result = $this->bind("insert");
                 } else {
                     $this->_pdo->exec($this->_sql) ? $result = 1 : ($result = 0);
                 }
                 break;
             case stripos($this->_sql, 'update'):
                 $this->_pdo->exec($this->_sql) ? $result = 1 : ($result = 0);
                 break;
             default:
                 return "Cann't exec()";
         }
         return $result;
     } catch (Exception $e) {
         throw Exeption::ThrowDb($e);
     }
 }
Exemplo n.º 2
0
 public function __construct($conn = "mysql")
 {
     try {
         $param_ini = new Config();
         switch ($conn) {
             case "mysql":
                 $this->_pdo = new PDO($param_ini->getVar('db.conn'), $param_ini->getVar('db.user'), $param_ini->getVar('db.pass'));
                 break;
             case "mssql":
                 $this->_pdo = new PDO($param_ini->getVar('db.conn_mssql'), $param_ini->getVar('db.user_mssql'), $param_ini->getVar('db.pass_mssql'));
                 break;
             default:
                 $this->_pdo = new PDO($param_ini->getVar('db.conn_' . $conn), $param_ini->getVar('db.user_' . $conn), $param_ini->getVar('db.pass_' . $conn));
         }
         //if ($conn == "mysql") $this->_pdo = new PDO($param_ini->getVar('db.conn'),$param_ini->getVar('db.user'),$param_ini->getVar('db.pass'));
         //if ($conn == "mssql") $this->_pdo = new PDO($param_ini->getVar('db.conn_mssql'),$param_ini->getVar('db.user_mssql'),$param_ini->getVar('db.pass_mssql'));
     } catch (\PDOException $e) {
         throw Exeption::ThrowDb($e);
     }
 }