execute() public method

执行语句 针对 INSERT, UPDATE 以及DELETE
public execute ( string $str ) : integer
$str string sql指令
return integer
Example #1
0
 /**
  * @param string $key
  */
 public function set($guildID, $key, $value)
 {
     $json = $this->getAll($guildID);
     $json->{$key} = $value;
     $data = json_encode($json);
     $this->db->execute("INSERT INTO settings (serverID, settings) VALUES (:serverID, :settings) ON DUPLICATE KEY UPDATE settings = :settings", array(":serverID" => $guildID, ":settings" => $data));
 }
Example #2
0
 /**
  * @return Model
  */
 public function synchronize()
 {
     $tables = $this->db->tables();
     if (false === array_search($this->table, $tables)) {
         $properties = array();
         foreach ($this->properties as $name => $instance) {
             if (is_subclass_of($instance, 'Property')) {
                 $properties[] = "`{$name}` " . $instance->__toString();
             }
         }
         $this->db->execute("CREATE TABLE `{$this->table}` (" . implode(', ', $properties) . ")");
     }
     return $this;
 }
Example #3
0
 public static function updatePassword($password)
 {
     $userID = user::getUserID();
     $password = self::genPassword($password);
     Db::execute("UPDATE zz_users SET password = :password WHERE id = :userID", array(":password" => $password, ":userID" => $userID));
     return "Updated password";
 }
Example #4
0
 public function process()
 {
     $db = new Db();
     $perishable_token = $this->generateToken();
     $query = "insert into user (email, password, perishable_token, last_activity_timestamp, signup_timestamp) values (" . "'" . $this->attributes['email'] . "', " . "'" . $this->attributes['password'] . "', " . "'" . $perishable_token . "', " . time() . ", " . time() . ")";
     return $db->execute($query);
 }
Example #5
0
 public static function updatePassword($password)
 {
     $userID = user::getUserID();
     $password = self::genPassword($password);
     Db::execute('UPDATE zz_users SET password = :password WHERE id = :userID', array(':password' => $password, ':userID' => $userID));
     return 'Updated password';
 }
Example #6
0
function UpdateRouteAssignment()
{
    $arrRouteAssignment = array('varRouteId' => $_POST['txtRouteId'], 'varRouteAssignment' => $_POST['txtRouteAssignment']);
    Db::execute('UPDATE routes SET assignment = :varRouteAssignment WHERE rtcode = :varRouteId', $arrRouteAssignment);
    $varResult = Db::getRow('SELECT * FROM routes WHERE rtcode = ?', $arrRouteAssignment['varRouteId']);
    echo 'Update Completed. Route assigned to ' . $varResult['assignment'];
}
Example #7
0
 public static function updatePoints($killID, $tempTables = false)
 {
     $points = self::calculatePoints($killID, $tempTables);
     $temp = $tempTables ? "_temporary" : "";
     Db::execute("update zz_participants{$temp} set points = :points where killID = :killID", array(":points" => $points, ":killID" => $killID));
     return $points;
 }
Example #8
0
    /**
     * @url POST profile/{userId}
     * @url PUT {userId}
     */
    protected function postProfile($userId, $firstname, $lastname, $nickname, $phone, $birthdate, $school, $province, $level, $purpose, $avatarId)
    {
        if ($userId == \TTO::getUserId()) {
            $statement = '
		  	UPDATE user SET
			  	firstname = :firstname,
			  	lastname  = :lastname, 
			  	nickname  = :nickname,
			  	phone     = :phone,
			  	birthdate = :birthdate,
			  	school    = :school,
			  	province  = :province,
			  	level     = :level,
			  	purpose   = :purpose,
			  	avatarId  = :avatarId
		  	WHERE userId = :userId
	  	';
            $bind = array('firstname' => $firstname, 'lastname' => $lastname, 'nickname' => $nickname, 'phone' => $phone, 'birthdate' => $birthdate, 'school' => $school, 'province' => $province, 'level' => $level, 'purpose' => $purpose, 'avatarId' => $avatarId, 'userId' => $userId);
            $row_update = \Db::execute($statement, $bind);
            \TTOMail::createAndSendAdmin('A user updated profile', json_encode($bind));
            $response = new \stdClass();
            $response->row_update = $row_update;
            return $response;
        } else {
            throw new RestException(401, 'No Authorize or Invalid request !!!');
        }
    }
Example #9
0
function irc_log($nick, $uhost, $command, $params)
{
    $id = Db::queryField("SELECT id FROM zz_irc_access WHERE name = :nick AND host = :uhost", "id", array(":nick" => $nick, ":uhost" => $uhost));
    if ($id == null) {
        $id = 0;
    }
    Db::execute("INSERT INTO zz_irc_log (id, nick, command, parameters) VALUES (:id, :nick, :command, :params)", array(":nick" => $nick, ":id" => $id, ":command" => $command, ":params" => implode(" ", $params)));
}
Example #10
0
 public static function cachePrimer()
 {
     Db::execute("set session wait_timeout = 120");
     self::storeResult(Db::query("select c.* from zz_characters c left join zz_participants p on (c.characterID = p.characterID) where dttm > date_sub(now(), interval 5 day) group by characterID", array(), 0), "select name from zz_characters where characterID = :id", ":id", "characterID", "name");
     self::storeResult(Db::query("select * from zz_corporations", array(), 0), "select name from zz_corporations where corporationID = :id", ":id", "corporationID", "name");
     self::storeResult(Db::query("select * from zz_alliances", array(), 0), "select name from zz_alliances where allianceID = :id", ":id", "allianceID", "name");
     self::storeResult(Db::query("select * from ccp_invTypes", array(), 0), "select typeName from invTypes where typeID = :typeID", ":typeID", "typeID", "typeName");
 }
 /**
  * @param string $sql
  * @param array $params
  * @return bool|ResultSet
  */
 protected function runSql($sql, $params = array())
 {
     $rez = $this->db->execute($sql, $params);
     if (!$rez) {
         $this->logError($this->db->lastError);
     }
     return $rez;
 }
Example #12
0
 /**
  * 定单处理
  * @param $tid 定单编号
  */
 public function handle($tid)
 {
     Db::table('balance')->where('tid', $tid)->update(array('status' => 1));
     //添加会员余额
     $balance = Db::table('balance')->where('siteid', SITEID)->where('tid', $tid)->first();
     $sql = "UPDATE " . tablename('member') . " SET credit2=credit2+{$balance['fee']} WHERE uid={$balance['uid']}";
     Db::execute($sql);
 }
Example #13
0
File: Model.php Project: frycnx/jxc
 /**
  * 删除数据
  *
  * @param string $table            
  * @param string $where            
  */
 public function delete($where = null, $table = '')
 {
     if (empty($table)) {
         $table = $this->table;
     }
     $sql = 'DELETE FROM ' . $table . (is_null($where) ? '' : ' WHERE ' . (is_array($where) ? implode(' AND ', $where) : $where));
     return $this->db->execute($sql);
 }
Example #14
0
function consumeNonce($form)
{
    $now = time();
    if (!isset($form['nonce']) || $form['nonce'] != $_SESSION['hg_nonce'] || !preg_match('/^\\d\\d\\d\\d-\\d\\d-\\d\\dT\\d\\d:\\d\\d:\\d\\dZ/', $form['nonce'], $ma) || !($timestamp = strtotime($ma[0])) || $timestamp > $now || $timestamp < $now - 60 * 60 || Db::scalarQuery('SELECT stamp FROM jos_oauthp_nonces WHERE nonce = ?', array($form['nonce']))) {
        //throw new Exception('Bad token', 405);
    }
    Db::execute('UPDATE jos_oauthp_nonces SET stamp = 1 WHERE nonce = ?', array($form['nonce']));
    unset($_SESSION['hg_nonce']);
}
Example #15
0
 public function save()
 {
     $params = json_encode($this->settings);
     $updateQuery = 'UPDATE jos_extensions SET params = ? WHERE `type`=\'component\' AND `element` = \'com_hubgraph\'';
     $insertQuery = 'INSERT INTO jos_extensions(name, `type`, `element`, params) VALUES (\'HubGraph\', \'component\', \'com_hubgraph\', ?)';
     if (!Db::update($updateQuery, array($params))) {
         Db::execute($insertQuery, array($params));
     }
 }
Example #16
0
function updateJEditableField($table, $field, $value, $id)
{
    $data = array('id' => $id, 'value' => $value);
    try {
        Db::execute("UPDATE {$table} SET {$field} = :value WHERE id = :id", $data);
        echo nl2br($value);
    } catch (Exception $e) {
        echo 'Error occured';
    }
}
Example #17
0
function addStatus()
{
    unset($_GET['action']);
    try {
        Db::execute("INSERT INTO status_names(name, WIP, serial)\n            VALUES(:name, :WIP, (select max(id) from status_names) + 1)", $_GET);
        response('success', Db::getLastInsertId());
    } catch (Exception $e) {
        response('error', $e->getMessage());
    }
}
Example #18
0
 function createNonce()
 {
     //set_include_path(get_include_path() . PATH_SEPARATOR . JPATH_BASE.'/libraries/openid');
     //require_once 'Auth/OpenID/Nonce.php';
     $now = time();
     $_SESSION['hg_nonce'] = sha1($now);
     //Auth_OpenID_mkNonce($now);
     Db::execute('INSERT INTO `#__oauthp_nonces` (created, nonce, stamp) VALUES (CURRENT_TIMESTAMP, ?, 0)', array($_SESSION['hg_nonce']));
     return $_SESSION['hg_nonce'];
 }
Example #19
0
 public function __construct()
 {
     //创建migration表用于记录动作
     if (!Schema::tableExists('migrations')) {
         $sql = "CREATE TABLE " . c('database.prefix') . 'migrations(migration varchar(255) not null,batch int)CHARSET UTF8';
         Db::execute($sql);
     }
     if (empty(self::$batch)) {
         self::$batch = Db::table('migrations')->max('batch') ?: 0;
     }
 }
Example #20
0
 public static function beSocial($killID)
 {
     if ($killID < 0) {
         return;
     }
     $ircMin = 5000000000;
     $twitMin = 10000000000;
     // This is an array of characters we like to laugh at :)
     $laugh = array(1633218082, 924610627, 619471207, 268946627, 179004085, 428663616);
     $count = Db::queryField("select count(*) count from zz_social where killID = :killID", "count", array(":killID" => $killID), 0);
     if ($count != 0) {
         return;
     }
     // Get victim info
     $victimInfo = Db::queryRow("select * from zz_participants where killID = :killID and isVictim = 1", array(":killID" => $killID));
     if ($victimInfo == null) {
         return;
     }
     $totalPrice = $victimInfo["total_price"];
     if (!in_array($victimInfo["characterID"], $laugh)) {
         // If in laugh array, skip the checks
         // Check the minimums, min. price and happened in last 12 hours
         if ($totalPrice < $ircMin) {
             return;
         }
     }
     Info::addInfo($victimInfo);
     $url = "https://zkillboard.com/detail/{$killID}/";
     if ($totalPrice >= $twitMin) {
         $url = Twit::shortenUrl($url);
     }
     $message = "|g|" . $victimInfo["shipName"] . "|n| worth |r|" . Util::formatIsk($totalPrice) . " ISK|n| was destroyed! {$url}";
     if (!isset($victimInfo["characterName"])) {
         $victimInfo["characterName"] = $victimInfo["corporationName"];
     }
     if (strlen($victimInfo["characterName"]) < 25) {
         $name = $victimInfo["characterName"];
         if (Util::endsWith($name, "s")) {
             $name .= "'";
         } else {
             $name .= "'s";
         }
         $message = "{$name} {$message}";
     }
     Db::execute("insert into zz_social (killID) values (:killID)", array(":killID" => $killID));
     Log::irc("{$message}");
     $message = Log::stripIRCColors($message);
     if ($totalPrice >= $twitMin) {
         $message .= " #tweetfleet #eveonline";
         $return = Twit::sendMessage($message);
         $twit = "https://twitter.com/eve_kill/status/" . $return->id;
         Log::irc("Message was also tweeted: |g|{$twit}");
     }
 }
Example #21
0
 /**
  * @param $password
  * @param $time
  */
 public function updateValuesInDatabase($password, $time, $browser)
 {
     $database = new Db();
     $username = $_SESSION[self::$setSessionUser];
     $database->query('UPDATE users SET cookie_password = :cookie_password, coockie_date = :cookie_date, browser = :browser WHERE username = :username');
     $database->bind(':username', $username);
     $database->bind(':cookie_password', $password);
     $database->bind(':cookie_date', $time);
     $database->bind(':browser', $browser);
     $database->execute();
 }
Example #22
0
function DropPagesTable()
{
    global $db_config;
    $db = new Db($db_config);
    $sql = <<<SQL
DROP TABLE IF EXISTS `pages`;
SQL;
    if ($db->execute($sql)) {
        echo "Pages table dropped successfully";
    } else {
        echo "Error: Could not drop pages table. Please try again";
    }
}
 public function execute($nick, $uhost, $channel, $command, $parameters, $nickAccessLevel)
 {
     $keyIDs = array();
     $entity = implode(" ", $parameters);
     if (sizeof($parameters) == 1 && (int) $parameters[0]) {
         $keyIDs[] = (int) $parameters[0];
     } else {
         // Perform a search
         $chars = array();
         $corps = array();
         $charResult = Db::query("select characterID from zz_characters where name = :s", array(":s" => $entity));
         foreach ($charResult as $char) {
             $chars[] = $char["characterID"];
         }
         foreach ($chars as $charID) {
             $corpID = Db::queryField("select corporationID from zz_participants where characterID = :c order by killID desc limit 1", "corporationID", array(":c" => $charID));
             if ($corpID !== null && $corpID > 0) {
                 $corps[] = $corpID;
             }
         }
         if (sizeof($chars)) {
             $keys = Db::query("select distinct keyID from zz_api_characters where isDirector = 'F' and characterID in (" . implode(",", $chars) . ")");
             foreach ($keys as $key) {
                 $keyIDs[] = $key["keyID"];
             }
         } else {
             $corpID = Db::queryField("select corporationID from zz_corporations where name = :s order by memberCount desc", "corporationID", array(":s" => $entity));
             if ($corpID !== null && $corpID > 0) {
                 $corps[] = $corpID;
             }
         }
         if (sizeof($corps)) {
             $keys = Db::query("select distinct keyID from zz_api_characters where isDirector = 'T' and corporationID in (" . implode(",", $corps) . ")");
             foreach ($keys as $key) {
                 $keyIDs[] = $key["keyID"];
             }
         }
     }
     if (sizeof($keyIDs) == 0) {
         irc_out("|r|Unable to locate any keys associated with {$entity} |n|");
     } else {
         $keyIDs = array_unique($keyIDs);
         sort($keyIDs);
         $key = sizeof($keyIDs) == 1 ? "keyID" : "keyIDs";
         $keys = implode(", ", $keyIDs);
         Db::execute("update zz_api set errorCode = 0, errorCount = 0, lastValidation = 0 where keyID in ({$keys})");
         if (sizeof($keyIDs)) {
             irc_out("Revalidating {$key}: {$keys}");
         }
     }
 }
Example #24
0
 public static function set($key, $value)
 {
     if (!User::isLoggedIn()) {
         throw new Exception("User is not logged in.");
     }
     $id = User::getUserID();
     self::$userConfig = null;
     if (is_null($value) || is_string($value) && strlen(trim($value)) == 0) {
         // Just remove the row and let the defaults take over
         return Db::execute("delete from zz_users_config where id = :id and locker = :key", array(":id" => $id, ":key" => $key));
     }
     $value = json_encode($value);
     return Db::execute("insert into zz_users_config (id, locker, content) values (:id, :key, :value)\n                                on duplicate key update content = :value", array(":id" => $id, ":key" => $key, ":value" => $value));
 }
Example #25
0
function CreateUser()
{
    global $db_config;
    $db = new Db($db_config);
    $sql = <<<SQL
INSERT INTO `users`
(`id`, `username`, `password`, `active`, `created_at`, `modified_at`)
VALUES
(%d, '%s', '%s', %d, '%s', '%s');
SQL;
    $sql = sprintf($sql, 1, $db->escString("adminone"), $db->escString(md5("password" . SALT)), 1, date('Y-m-d h:i:s'), date('Y-m-d h:i:s'));
    $db->execute($sql);
    echo "User created successfully";
}
Example #26
0
    /**
     * @url POST removenotification
     */
    protected function postRemoveNotification($userId, $routeUrl, $fromUserId)
    {
        $statement = '
			DELETE FROM notification
			 WHERE userId     = :userId
			   AND routeUrl   = :routeUrl
			   AND fromUserId = :fromUserId
		';
        $bind = array('userId' => $userId, 'routeUrl' => $routeUrl, 'fromUserId' => $fromUserId);
        \Db::execute($statement, $bind);
        $statement = '
			UPDATE user SET notificationCount = notificationCount - 1
			WHERE userId = :userId
		';
        $bind = array('userId' => $userId);
        \Db::execute($statement, $bind);
    }
Example #27
0
 /**
  * @url POST
  * @url POST /user/{userId}
  */
 protected function addSection($courseId, $name, $description, $seq, $userId = null)
 {
     if (\TTO::getRole() == 'admin') {
         $statement = '
     INSERT INTO section (courseId, name, description, seq)
     VALUES (:courseId, :name, :description, :seq)
   ';
         $bind = array('courseId' => $courseId, 'name' => $name, 'description' => $description, 'seq' => $seq);
         \Db::execute($statement, $bind);
         $sectionId = \Db::getLastInsertId();
         $statement = 'SELECT * FROM section WHERE sectionId = :sectionId';
         $bind = array('sectionId' => $sectionId);
         return \Db::getRow($statement, $bind);
     } else {
         throw new RestException(401, 'No Authorize or Invalid request !!!');
     }
 }
Example #28
0
 public function move($new)
 {
     if (!$this->found) {
         return false;
     }
     if ($this->posicion == $new) {
         return false;
     }
     if ($this->posicion > $new) {
         Db::execute("UPDATE `inmuebles_fotos`\n                 SET `posicion` = `posicion` + 1\n                 WHERE `posicion` < {$this->posicion}\n                   AND `posicion` >= {$new}\n                   AND `inmueble_id` = {$this->inmueble_id}");
     } else {
         Db::execute("UPDATE `inmuebles_fotos`\n                 SET `posicion` = `posicion` - 1\n                 WHERE `posicion` > {$this->posicion}\n                   AND `posicion` <= {$new}\n                   AND `inmueble_id` = {$this->inmueble_id}");
     }
     $this->posicion = $new;
     $this->update();
     return true;
 }
Example #29
0
function createProject()
{
    $name = strval($_GET['project']);
    if (empty($name)) {
        return response('error', 'Empty project name');
    }
    $exist = Db::getValue('SELECT count(id) from projects where name= ?', $name);
    if ($exist) {
        return response('error', 'Project name already exist');
    }
    // Insert project
    $data = array('name' => $name, 'status' => 'active');
    Db::execute('INSERT INTO projects(name, status) VALUES(:name, :status)', $data);
    $insertId = Db::getLastInsertId();
    if ($insertId) {
        return response('success', $insertId);
    }
    return response('error', 'Something went wrong! please try again.');
}
Example #30
0
 /**
  * Register a new user if username doesn't already exist
  *
  * @param \model\RegisterUser $credential
  * @param \model\IregisterListener $listener
  * @return bool
  */
 public function doRegister(\model\RegisterUser $credential, model\IregisterListener $listener)
 {
     $username = $credential->getUsername();
     $records = new Db();
     $records->query('SELECT username,password FROM users WHERE username = :username');
     $records->bind(':username', $username);
     $records->resultset();
     if ($records->rowCount() > 0) {
         $listener->userExist("RegisterModel::UserAlreadyExistException");
     } else {
         $password = password_hash($credential->getPassword(), PASSWORD_BCRYPT);
         $records->query('INSERT INTO users (username, password) VALUES (:username, :password)');
         $records->bind(':username', $username);
         $records->bind(':password', $password);
         $records->execute();
         $_SESSION[self::$newUsername] = $username;
         return true;
     }
 }