本文整理汇总了PHP中DB::affected_rows方法的典型用法代码示例。如果您正苦于以下问题:PHP DB::affected_rows方法的具体用法?PHP DB::affected_rows怎么用?PHP DB::affected_rows使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DB
的用法示例。
在下文中一共展示了DB::affected_rows方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testMultipleRowInsert
public function testMultipleRowInsert()
{
$query = SQLInsert::create('"SQLInsertTestBase"');
$query->addRow(array('"Title"' => 'First Object', '"Age"' => 10, '"Description"' => 'First the worst'));
$query->addRow(array('"Title"' => 'Second object', '"Age"' => 12));
$sql = $query->sql($parameters);
// Only test this case if using the default query builder
if (get_class(DB::get_conn()->getQueryBuilder()) === 'DBQueryBuilder') {
$this->assertSQLEquals('INSERT INTO "SQLInsertTestBase" ("Title", "Age", "Description") VALUES (?, ?, ?), (?, ?, ?)', $sql);
}
$this->assertEquals(array('First Object', 10, 'First the worst', 'Second object', 12, null), $parameters);
$query->execute();
$this->assertEquals(2, DB::affected_rows());
// Check inserted objects are correct
$firstObject = DataObject::get_one('SQLInsertTestBase', array('"Title"' => 'First Object'), false);
$this->assertNotEmpty($firstObject);
$this->assertEquals($firstObject->Title, 'First Object');
$this->assertEquals($firstObject->Age, 10);
$this->assertEquals($firstObject->Description, 'First the worst');
$secondObject = DataObject::get_one('SQLInsertTestBase', array('"Title"' => 'Second object'), false);
$this->assertNotEmpty($secondObject);
$this->assertEquals($secondObject->Title, 'Second object');
$this->assertEquals($secondObject->Age, 12);
$this->assertEmpty($secondObject->Description);
}
示例2: __construct
function __construct()
{
global $oDB;
Form::Form('MoveNewsCatForm');
$catid = Url::get('id', 0);
if ($catid) {
$category = DB::select('news_categories', $catid);
$cmd = Url::get('cmd');
if ($category) {
if ($cmd == 'move_up') {
if ($category['position'] > 1) {
DB::query("UPDATE news_categories SET position=position-1 WHERE id=" . $category['id']);
if (DB::affected_rows()) {
DB::query("UPDATE news_categories SET position=position+1 WHERE id!=" . $category['id'] . " AND position=" . ($category['position'] - 1));
}
}
} else {
if ($category['position'] < DB::count("news_categories")) {
DB::query("UPDATE news_categories SET position=position+1 WHERE id=" . $category['id']);
if (DB::affected_rows()) {
DB::query("UPDATE news_categories SET position=position-1 WHERE id!=" . $category['id'] . " AND position=" . ($category['position'] + 1));
}
}
}
AZLib::getNewsCats(1);
}
}
Url::redirect_current();
}
示例3: query
static function query($sql)
{
if(func_num_args()>1) $sql = self::prepare($args = func_get_args());
$st = microtime(true);
$result = mysql_query($sql);
if(mysql_error()) DB::error($sql);
self::$affected_rows = mysql_affected_rows();
self::$insert_id = mysql_insert_id();
/*
if(microtime(true) - $st > 1)
{
$_q = preg_replace('/[\d,]+/', 'N', $sql);
$_uri = Request::escape( $_SERVER['REQUEST_URI'] );
$_long_query = DB::prepare("insert into long_query (q,uri,st) values (?,?,?i)", $_q, $_uri, microtime(true)-$st);
mysql_query($_long_query); // служедбный запрос, чтобы не сбил нам insert_id и affected_rows
}
*/
// echo $sql."<br>\n";
if(microtime(true)-$st>0.1 && $_SERVER['REMOTE_ADDR']=='93.125.42.170') $GLOBALS['queries'][] = Array("time"=>(microtime(true)-$st), "sql"=>$sql);
return $result;
}
示例4: sql_runquery
function sql_runquery()
{
global $_G;
if ($_GET['onsubmit'] && check() && $_GET['query_string']) {
$query_string = trim($_GET['query_string']);
if (strstr($query_string, ';')) {
$query_string = explode(';', $query_string);
}
$query_string = (array) $query_string;
$update = true;
$msg = '';
$query_string = array_filter($query_string);
$query_string = array_unique($query_string);
$i = 0;
foreach ($query_string as $k => $v) {
if ($v) {
$cmd = trim(strtoupper(substr($v, 0, strpos($v, ' '))));
if ($cmd === 'UPDATE' || $cmd === 'DELETE') {
$update = false;
}
DB::query($v, array(), $update);
$msg .= '<p>' . $v . ',影响行数:' . DB::affected_rows() . '</p>';
$i++;
}
}
cpmsg('成功执行:' . $i . '条SQL语句' . $msg, 'success', 'm=' . __CLASS__ . '&a=' . __FUNCTION__, '', "<p claaa='red'>如果更改了某些系统数据,请手动更新系统缓存</p>");
return false;
}
$this->show();
}
示例5: statistic
function statistic()
{
if (empty($this->tableName)) {
return false;
}
$ip = $GLOBALS['_J']['client_ip'];
$timestamp = time();
$sql = "UPDATE " . $this->tableName . "\r\n\t\t\tset\r\n\t\t\t`times`=`times`+1,\r\n\t\t\t`last_visit`='{$timestamp}'\r\n\t\t\twhere `name`='{$this->robotName}'";
DB::query($sql, 'SILENT');
$result = DB::affected_rows();
if ($result < 1) {
$sql = "insert into {$this->tableName}(`name`,`times`,`first_visit`,`last_visit`,`agent`)\r\n\t\t\tvalues('{$this->robotName}','1','{$timestamp}','{$timestamp}','{$this->agent}')";
DB::query($sql);
$result = (bool) DB::affected_rows();
}
if ($result) {
$sql = "\r\n\t\t\tUPDATE {$this->tableName}_ip\r\n\t\t\tset\r\n\t\t\t\t`times`=`times`+1,\r\n\t\t\t\t`last_visit`='{$timestamp}'\r\n\t\t\twhere\r\n\t\t\t\t`ip`='{$ip}'\r\n\t\t\t";
DB::query($sql, 'SILENT');
$result = DB::affected_rows();
if ($result < 1) {
$sql = "insert into\r\n\t\t\t\t{$this->tableName}_ip(`ip`,`name`,`times`,`first_visit`,`last_visit`)\r\n\t\t\t\tvalues('{$ip}','{$this->robotName}','1','{$timestamp}','{$timestamp}')";
DB::query($sql);
$result = (bool) DB::affected_rows();
}
}
return $result;
}
示例6: update_onlinetime
public function update_onlinetime($uid, $total, $thismonth, $lastupdate)
{
if ($uid = intval($uid)) {
DB::query("UPDATE " . DB::table('common_onlinetime') . "\r\n\t\t\tSET total=total+'{$total}', thismonth=thismonth+'{$thismonth}', lastupdate='" . $lastupdate . "' WHERE " . DB::field($this->_pk, $uid));
return DB::affected_rows();
}
return false;
}
示例7: activate_participation
/**
* activate area participation
*/
public function activate_participation() {
$sql = "UPDATE participant SET activated=current_date WHERE member=".intval(Login::$member->id)." AND area=".intval($this->id);
$result = DB::query($sql);
if ( !DB::affected_rows($result) ) {
$sql = "INSERT INTO participant (member, area) VALUES (".intval(Login::$member->id).", ".intval($this->id).")";
DB::query($sql);
}
$this->update_participants_cache();
}
示例8: write
public function write($sess_id, $sess_data)
{
global $user;
// If saving of session data is disabled or if the client doesn't have a session,
// and one isn't being created ($value), do nothing. This keeps crawlers out of
// the session table. This reduces memory and server load, and gives more useful
// statistics. We can't eliminate anonymous session table rows without breaking
// the throttle module and the "Who's Online" block.
if (!$this->is_save_session() || empty($_COOKIE[session_name()]) && empty($sess_data)) {
return TRUE;
}
$this->_db->query("UPDATE `{$this->_dbtable}` SET `uid`=%d, `lasttime`=%d, `lastip`='%s', `data`='%s' WHERE `sid`='%s'", $user->uid, $this->_timestamp, get_clientip(), $sess_data, $sess_id);
if (!$this->_db->affected_rows()) {
//update error, indicating no the session
$this->_db->query("INSERT INTO `{$this->_dbtable}` (`sid`, `uid`, `lasttime`, `lastip`, `data`) VALUES('%s', %d, %d, '%s', '%s')", $sess_id, $user->uid, $this->_timestamp, get_clientip(), $sess_data);
}
return TRUE;
}
示例9: testBasicUpdate
public function testBasicUpdate()
{
$query = SQLUpdate::create()->setTable('"SQLUpdateTestBase"')->assign('"Description"', 'Description 1a')->addWhere(array('"Title" = ?' => 'Object 1'));
$sql = $query->sql($parameters);
// Check SQL
$this->assertSQLEquals('UPDATE "SQLUpdateTestBase" SET "Description" = ? WHERE ("Title" = ?)', $sql);
$this->assertEquals(array('Description 1a', 'Object 1'), $parameters);
// Check affected rows
$query->execute();
$this->assertEquals(1, DB::affected_rows());
// Check item updated
$item = DataObject::get_one('SQLUpdateTestBase', array('"Title"' => 'Object 1'));
$this->assertEquals('Description 1a', $item->Description);
}
示例10: make
function make($rule = '', $num = 1, $cardval = array())
{
global $_G;
$this->rule = empty($rule) ? $this->set['rule'] : trim($rule);
if (empty($this->rule)) {
return -1;
}
$this->fail($num);
if (is_array($cardval)) {
foreach ($cardval as $key => $val) {
$sqlkey .= ", {$key}";
$sqlval .= ", '{$val}'";
}
}
for ($i = 0; $i < $num; $i++) {
if ($this->checkrule($this->rule)) {
$card = $this->rule;
foreach ($this->rulereturn as $key => $val) {
$search = array();
foreach ($val as $skey => $sval) {
$search[] = '/' . $this->rulekey[$key] . '/';
}
$card = preg_replace($search, $val, $card, 1);
}
} else {
return 0;
}
$sql = "INSERT INTO " . DB::table('common_card') . " (id, makeruid, dateline {$sqlkey})VALUES('{$card}', '{$_G['uid']}', '{$_G['timestamp']}' {$sqlval})";
DB::query($sql, 'SILENT');
if ($sqlerror = DB::error()) {
if (DB::errno() == 1062) {
$this->fail++;
if ($this->failmin > $this->fail) {
$num++;
} else {
$num = $i - 1;
}
} else {
DB::halt($sqlerror, $sql);
}
} else {
$this->succeed += intval(DB::affected_rows());
$this->cardlist[] = $card;
}
}
return true;
}
示例11: updatesession
function updatesession($force = false)
{
global $_G;
static $updated = false;
if (!$updated) {
if ($_G['uid']) {
if ($_G['cookie']['ulastactivity']) {
$ulastactivity = authcode($_G['cookie']['ulastactivity'], 'DECODE');
} else {
$ulastactivity = getuserprofile('lastactivity');
dsetcookie('ulastactivity', authcode($ulastactivity, 'ENCODE'), 31536000);
}
}
$discuz =& discuz_core::instance();
$oltimespan = $_G['setting']['oltimespan'];
//vot //$lastolupdate = $discuz->session->var['lastolupdate'];
/*vot*/
$lastolupdate = DB::result_first("SELECT lastupdate FROM " . DB::table('common_onlinetime') . " WHERE uid='{$_G['uid']}'");
if ($_G['uid'] && $oltimespan && TIMESTAMP - ($lastolupdate ? $lastolupdate : $ulastactivity) > $oltimespan * 60) {
DB::query("UPDATE " . DB::table('common_onlinetime') . "\r\n\t\t\t\tSET total=total+'{$oltimespan}', thismonth=thismonth+'{$oltimespan}', lastupdate='" . TIMESTAMP . "'\r\n\t\t\t\tWHERE uid='{$_G['uid']}'");
if (!DB::affected_rows()) {
DB::insert('common_onlinetime', array('uid' => $_G['uid'], 'thismonth' => $oltimespan, 'total' => $oltimespan, 'lastupdate' => TIMESTAMP));
}
$discuz->session->set('lastolupdate', TIMESTAMP);
}
foreach ($discuz->session->var as $k => $v) {
if (isset($_G['member'][$k]) && $k != 'lastactivity') {
$discuz->session->set($k, $_G['member'][$k]);
}
}
foreach ($_G['action'] as $k => $v) {
$discuz->session->set($k, $v);
}
$discuz->session->update();
$updated = true;
if ($_G['uid'] && TIMESTAMP - $ulastactivity > 21600) {
if ($oltimespan && TIMESTAMP - $ulastactivity > 43200) {
$total = DB::result_first("SELECT total FROM " . DB::table('common_onlinetime') . " WHERE uid='{$_G['uid']}'");
DB::update('common_member_count', array('oltime' => round(intval($total) / 60)), "uid='{$_G['uid']}'", 1);
//vot dsetcookie('ulastactivity', authcode(TIMESTAMP, 'ENCODE'), 31536000);
}
dsetcookie('ulastactivity', authcode(TIMESTAMP, 'ENCODE'), 31536000);
DB::update('common_member_status', array('lastip' => $_G['clientip'], 'lastactivity' => TIMESTAMP, 'lastvisit' => TIMESTAMP), "uid='{$_G['uid']}'", 1);
}
}
return $updated;
}
示例12: statistic
function statistic()
{
if (empty($this->tableName)) {
return false;
}
$timestamp = time();
$sql = "UPDATE " . $this->tableName . " \r\n\t\t\tset \r\n\t\t\t`times`=`times`+1,\r\n\t\t\t`last_visit`={$timestamp}\r\n\t\t\twhere `name`='{$this->robotName}' and `date`='{$this->date}'";
DB::query($sql, 'SILENT');
$result = DB::affected_rows();
if ($result > 0) {
return true;
}
$sql = "insert into {$this->tableName}(`name`,`times`,`date`,`first_visit`,`last_visit`) \r\n\t\tvalues('{$this->robotName}','1','{$this->date}','{$timestamp}','{$timestamp}')";
DB::query($sql, 'SILENT');
$result = (bool) DB::affected_rows();
return $result;
}
示例13: testAffectedRows
public function testAffectedRows()
{
if (!DB::get_connector() instanceof PDOConnector) {
$this->markTestSkipped('This test requires the current DB connector is PDO');
}
$query = new SQLUpdate('MySQLDatabaseTest_Data');
$query->setAssignments(array('Title' => 'New Title'));
// Test update which affects no rows
$query->setWhere(array('Title' => 'Bob'));
$result = $query->execute();
$this->assertInstanceOf('PDOQuery', $result);
$this->assertEquals(0, DB::affected_rows());
// Test update which affects some rows
$query->setWhere(array('Title' => 'First Item'));
$result = $query->execute();
$this->assertInstanceOf('PDOQuery', $result);
$this->assertEquals(1, DB::affected_rows());
}
示例14: make
function make($rule = '', $num = 1, $cardval = array())
{
global $_G;
$this->rule = empty($rule) ? $this->set['rule'] : trim($rule);
if (empty($this->rule)) {
return -1;
}
$this->fail($num);
$cardval['makeruid'] = $_G['uid'];
$cardval['dateline'] = $_G['timestamp'];
for ($i = 0; $i < $num; $i++) {
if ($this->checkrule($this->rule)) {
$card = $this->rule;
foreach ($this->rulereturn as $key => $val) {
$search = array();
foreach ($val as $skey => $sval) {
$search[] = '/' . $this->rulekey[$key] . '/';
}
$card = preg_replace($search, $val, $card, 1);
}
} else {
return 0;
}
$cardval['id'] = $card;
C::t('common_card')->insert($cardval, false, false, 'SILENT');
if ($sqlerror = DB::error()) {
if ($sqlerror == 1062) {
$this->fail++;
if ($this->failmin > $this->fail) {
$num++;
} else {
$num = $i - 1;
}
}
/* else {
DB::halt($sqlerror, $sql);
}*/
} else {
$this->succeed += intval(DB::affected_rows());
$this->cardlist[] = $card;
}
}
return true;
}
示例15: friend_delete
function friend_delete($touid)
{
global $_G;
if (!friend_check($touid)) {
return false;
}
DB::delete('home_friend', "(uid='{$_G['uid']}' AND fuid='{$touid}') OR (fuid='{$_G['uid']}' AND uid='{$touid}')");
if (DB::affected_rows()) {
addfriendlog($_G['uid'], $touid, 'delete');
friend_cache($_G['uid']);
friend_cache($touid);
}
}