MysqliDb::update PHP Method

update() public method

Update query. Be sure to first call the "where" method.
public update ( string $tableName, array $tableData, integer $numRows = null ) : boolean
$tableName string The name of the database table to work with.
$tableData array Array of data to update the desired row.
$numRows integer Limit on the number of rows that can be updated.
return boolean
    public function update($tableName, $tableData, $numRows = null)
    {
        if ($this->isSubQuery) {
            return;
        }
        $this->_query = "UPDATE " . self::$prefix . $tableName;
        $stmt = $this->_buildQuery($numRows, $tableData);
        $status = $stmt->execute();
        $this->reset();
        $this->_stmtError = $stmt->error;
        $this->_stmtErrno = $stmt->errno;
        $this->count = $stmt->affected_rows;
        return $status;
    }

Usage Example

コード例 #1
0
ファイル: alipay.php プロジェクト: szgongyi/TrafficPolice-Web
function order_paid()
{
    require_once './submodules/php-mysqli-database-class/MysqliDb.php';
    require './includes/config.php';
    $db = new MysqliDb($db_host, $db_user, $db_pass, $db_name);
    $payid = $_GET['out_trade_no'];
    $aPayId = explode('_', $payid);
    $mtrid = $aPayId[1];
    $params = json_encode($_GET);
    //验证是否已经支付过
    $db->where("mtr_id = '{$mtrid}'")->get('mark_trafficpolice_reward');
    if ($db->count == 0) {
        $aNew = array('mtr_id' => $mtrid, 'pay_id' => $payid, 'pay_success' => 1, 'pay_money' => $_GET['total_fee'], 'pay_date' => $_GET['gmt_payment'], 'pay_params' => $params, 'created_date' => $db->now());
        $id = $db->insert('mark_trafficpolice_reward', $aNew);
        //给用户增加余额
        $sql = "SELECT mt.user_id,u.user_money FROM `mark_trafficpolice` mt\n            LEFT JOIN mark_trafficpolice_received mtr ON mt.id=mtr.mt_id\n            LEFT JOIN users u ON u.user_id=mt.user_id\n            WHERE mtr.id= '{$mtrid}'";
        $aUser = $db->rawQuery($sql);
        if ($db->count) {
            $aUpdate = array('user_money' => $aUser[0]['user_money'] + $_GET['total_fee'], 'updated_date' => $db->now());
            $db->where('user_id', $aUser[0]['user_id']);
            $db->update('users', $aUpdate);
        }
    } else {
        echo "already rewarded";
    }
}
All Usage Examples Of MysqliDb::update