Ejemplo n.º 1
0
 /**
  * function description
  * 
  * @param
  * @return void
  */
 public function execute()
 {
     $sql = $this->genSql();
     $ret = false;
     Sp_Log::debug(__CLASS__ . '->' . __FUNCTION__ . ': ' . $sql);
     $dbh = $this->getDbh();
     //var_dump($dbh);
     $input_parms = $this->getParams();
     //var_dump($input_parms);
     if (is_array($input_parms) && count($input_parms) > 0) {
         $sth = $dbh->prepare($sql);
         //print_r($this->parms($sql,$input_parms));exit;
         if (!$sth) {
             Sp_Log::warning('table: ' . $this->_table_key . ',' . __CLASS__ . '->' . __FUNCTION__ . ': ' . print_r($sth->errorInfo(), true));
         }
         $ret = $sth->execute($input_parms);
         if ($ret && in_array($this->_operate, array('UPDATE', 'DELETE'))) {
             return $sth->rowCount();
         }
     } else {
         //echo $sql;
         $ret = $dbh->exec($sql);
     }
     if (!$ret) {
         Sp_Log::warning('table: ' . $this->_table_key . ',' . __CLASS__ . '->' . __FUNCTION__ . ': ' . print_r($dbh->errorInfo(), true));
     }
     if ($ret && $this->_operate == 'INSERT' && $dbh->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql') {
         $ret = $dbh->lastInsertId();
     }
     return $ret;
 }
    foreach (Da_Wrapper::getDbos() as $key => $dbo) {
        echo $key, ":\n";
        echo 'class: ', get_class($dbo), ":\n";
        print_r($dbo->errorInfo());
        if (property_exists($dbo, 'logs')) {
            echo 'logs:', PHP_EOL;
            print_r($dbo->logs);
        }
        //echo 'querynum: ', $dbo->querynum, ":\n";
        //print_r($dbo->queries);
    }
    echo "\n-->\n";
}
if (class_exists('Db_Factory', false)) {
    //var_dump(Db_Factory::getDbos());
    foreach (Db_Factory::getDbos() as $key => $dbo) {
        echo "<!-- \n";
        echo $key, ":\n";
        echo 'class: ', get_class($dbo), ":\n";
        echo 'querynum: ', $dbo->querynum, ":\n";
        print_r($dbo->queries);
        echo "\n-->\n";
    }
}
if (class_exists('Sp_Log', false)) {
    echo "<!-- logs:\n", print_r(Sp_Log::getLogs(), true), "\n-->\n";
}
//var_dump(xdebug_get_declared_vars());
if (isset($_SERVER['HTTP_HOST'])) {
    echo "</div>";
}
Ejemplo n.º 3
0
 /**
  * function description
  * 
  * @param
  * @return void
  */
 private function getDoSth($count = false)
 {
     $sql = $this->genSql($count);
     Sp_Log::debug(__CLASS__ . '->' . __FUNCTION__ . ': ' . $sql);
     $dbh = $this->getDbh();
     //var_dump($dbh);
     $input_parms = $this->getParams();
     //var_dump($input_parms);
     if (is_array($input_parms) && count($input_parms) > 0) {
         $sth = $dbh->prepare($sql);
         $ret = $sth->execute($input_parms);
         if (!$ret) {
             Sp_Log::warning(__CLASS__ . '->' . __FUNCTION__ . ' execute: ' . print_r($sth->errorInfo(), true));
         }
     } else {
         $sth = $dbh->query($sql);
         if (!$sth) {
             Sp_Log::warning(__CLASS__ . '->' . __FUNCTION__ . ' query: ' . print_r($dbh->errorInfo(), true));
         }
     }
     if (!$sth) {
         Sp_Log::warning(__CLASS__ . '->' . __FUNCTION__ . ' table : ' . $this->_table . ', : ' . print_r($dbh->errorInfo(), true));
     }
     return $sth;
 }
Ejemplo n.º 4
0
 /**
  * 根据登录名和密码,验证用户
  *
  * @param string $username
  * @param string $password
  * @param array $option = null
  * @return mixed 成功返回对象,失败返回 负数或FALSE
  */
 public static function authenticate($username, $password, $option = null)
 {
     $src_id = isset($option['src_id']) ? $option['src_id'] : 0;
     $username = trim($username);
     if (!$username) {
         return parent::ERR_USERNAME_NOT_FOUND;
     }
     $patternMobile = Sp_Dictionary::getOtherOption('patternMobile');
     $patternEmail = Sp_Dictionary::getOtherOption('patternEmail');
     if (preg_match($patternMobile, $username)) {
         $field_name = 'mobile';
     } elseif (preg_match($patternEmail, $username)) {
         $field_name = 'email';
     } else {
         $field_name = 'userid';
     }
     $user = self::load($username, $field_name, $src_id);
     if ($user->valid()) {
         $crypted_password = self::encrypt($password, $user->kid);
         if ($crypted_password == trim($user->pwd)) {
             if ($user->status == 1) {
                 return parent::ERR_ACCOUNT_DISABLED;
             }
             return $user;
         } else {
             Sp_Log::notice('password incorrect: ' . $crypted_password . ' - ' . $user['pwd']);
             return parent::ERR_PASSWORD_INCORRECT;
         }
     }
     return parent::ERR_USERNAME_NOT_FOUND;
 }
Ejemplo n.º 5
0
 /**
  * 执行一条SQL,并返回 Statment 对象
  *
  * @param string $table_key
  * @param string $sql
  * @param array $params
  * @return object
  */
 public static function query($table_key, $sql, $params = null)
 {
     $dbh = self::dbo($table_key);
     self::injectLog($dbh, $sql);
     $sql = self::prefixTableName($sql, $dbh->table_prefix);
     if (is_null($params) || !is_array($params) || count($params) == 0) {
         $sth = $dbh->query($sql);
     } else {
         $sth = $dbh->prepare($sql);
         if ($sth) {
             $sth->execute($params);
         }
     }
     if (!$sth) {
         Sp_Log::warning(__CLASS__ . '::' . __FUNCTION__ . ' : ' . print_r($dbh->errorInfo(), true) . "\n" . $table_key . ': ' . $sql);
         return false;
     }
     return $sth;
 }