本文整理汇总了PHP中Service::getDB方法的典型用法代码示例。如果您正苦于以下问题:PHP Service::getDB方法的具体用法?PHP Service::getDB怎么用?PHP Service::getDB使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Service
的用法示例。
在下文中一共展示了Service::getDB方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
/**
* Saves a token
*
* @return mixed (boolean/integer) false if failed
*/
public function save()
{
$this->token = $this->generateToken();
$this->date = $this->now();
$dataToSave = array();
$q = "select `id` from `" . $this->table . "` where `app`='" . $this->app . "' LIMIT 1";
$rows = Service::getDB()->query($q);
foreach ($this->attributes as $attr) {
$k = $attr[0];
$dataToSave[$k] = $this->{$k};
}
if (sizeof($rows) > 0) {
Service::getDB()->where('id', $rows[0]['id']);
$insertId = Service::getDB()->update($this->table, $dataToSave);
} else {
$insertId = Service::getDB()->insert($this->table, $dataToSave);
}
if ($this->id == "") {
$this->id = $insertId;
}
return $this->token;
}
示例2: addStock
/**
* Adds stock items to the company
* @param integer $quantity amount of stock to be added
* @param integer $type can be RESOURCE or PRODUCT
*
* @return boolean if added
*/
public function addStock($quantity, $type)
{
$db = Service::getDB();
$where = array('company' => $this->id, 'product' => $this->product, 'productType' => $type);
if ($type == Company::PRODUCT_TYPE_PRODUCT) {
$condition = "AND quality='" . $this->quality . "' ";
$where['quality'] = $this->quality;
} else {
$condition = "";
$where['quality'] = 0;
}
$r = $db->query("SELECT quantity FROM company_stock WHERE company='" . $this->id . "' AND product='" . $this->product . "' AND productType='" . $type . "' " . $condition);
if (sizeof($r) == 0) {
$stock = $quantity;
$where['quantity'] = $stock;
return $db > insert('company_stock', $where);
} else {
$stock = $r[0]['quantity'] + $quantity;
$data = array('quantity' => $stock);
$db->where($where);
return $db->update('company_stock', $data);
}
}
示例3: saveNew
/**
* creates a new user
*
* @return mixed (uid or false)
*/
public function saveNew()
{
$this->status = self::STATUS_PENDING;
$this->gold = 0;
$this->xp = 0;
$this->language = 'en';
$q = "select `id` from `" . $this->table . "` where `email`='" . $this->email . "' OR `nick`='" . $this->nick . "' LIMIT 1";
$rows = Service::getDB()->query($q);
if (sizeof($rows) > 0) {
return false;
}
return parent::saveNew();
}
示例4: delete
/**
* Deletes the object from the database
* @return boolean
*/
function delete()
{
Service::getDB()->where('id', $this->id);
return Service::getDB()->delete($this->table, 1);
}