本文整理汇总了PHP中CDatabase::getDatabase方法的典型用法代码示例。如果您正苦于以下问题:PHP CDatabase::getDatabase方法的具体用法?PHP CDatabase::getDatabase怎么用?PHP CDatabase::getDatabase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CDatabase
的用法示例。
在下文中一共展示了CDatabase::getDatabase方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: change
public function change($parameter_a)
{
$product_list = $parameter_a['product_list'] ? $parameter_a['product_list'] : "a:0:{}";
/*
* $db = CDatabase::getInstance();
* $db->query("update sk_admin_group set gname='{$parameter_a['roleName']}',rightList='{$parameter_a['rights']}',product_list='{$product_list}',parent_id='{$parameter_a['parent_id']}' where gid='{$parameter_a['id']}'");
*/
try {
$pdo = CDatabase::getDatabase();
$pdo_runObject = $pdo->prepare("update sk_admin_group set gname=?,rightList=?,product_list=?,parent_id=? where gid=?");
$pdo_runObject->bindParam(1, $parameter_a['roleName'], PDO::PARAM_STR);
$pdo_runObject->bindParam(2, $parameter_a['rights'], PDO::PARAM_STR);
$pdo_runObject->bindParam(3, $product_list, PDO::PARAM_STR);
$pdo_runObject->bindParam(4, $parameter_a['parent_id'], PDO::PARAM_STR);
$pdo_runObject->bindParam(5, $parameter_a['id'], PDO::PARAM_INT);
$result_status = $pdo_runObject->execute();
} catch (PDOException $e) {
echo $e->getMessage();
}
return $result_status;
}
示例2: save
/**
* 保存对象
*/
public function save()
{
$publicAttributeList = $this->_getAllSetAttribute();
$tableName = $this->_getTableName();
$condition = $this->condition;
$params = $this->params;
$where = $this->where;
if (!empty($condition)) {
$updateStr = '';
foreach ($publicAttributeList as $key => $val) {
$updateStr .= '`' . $key . '` = \'' . $val . '\' ,';
}
$updateStr = substr($updateStr, 0, -1);
$dbConfig = CDatabase::$configData[1];
$tablePre = isset($dbConfig['tablePrefix']) ? $dbConfig['tablePrefix'] : '';
$updateSql = 'UPDATE `' . $tablePre . $tableName . '` SET ' . $updateStr . ' WHERE ' . $condition;
$result = CDatabase::getDatabase()->prepare($updateSql)->execute($params);
if (!$result) {
throw new CDbException('[查询错误]调用ActiveRecord->save()方法时,执行SQL错误[' . $updateSql . ']');
}
} else {
if (!empty($where)) {
$result = CDatabase::getInstance()->update()->from($tableName)->value($publicAttributeList)->where($where)->execute();
} else {
$result = CDatabase::getInstance()->insert()->from($tableName)->value($publicAttributeList)->execute();
}
}
//$this->_clearAttribute();
return $result;
}
示例3: rollback
/**
* 回滚一个事物
*/
public function rollback()
{
//使用主库
$databaseObject = CDatabase::getDatabase($this->configName, true);
return $databaseObject->rollback();
}
示例4: Action_delRights
/**
* 删除资源
*/
public function Action_delRights()
{
$id = $this->Args('id', 'int');
$status = CModel::factory('adminRightsModel')->delete(array('id' => $id));
if (false == $status) {
$errorMessage = CDatabase::getDatabase()->errorInfo();
$errorMessage = isset($errorMessage[2]) ? $errorMessage[2] : '';
}
$this->displayAjax($status, $errorMessage);
}
示例5: change
public function change($parameter_a)
{
$db = CDatabase::getDatabase();
// $prepare_re=$db->prepare("update sk_admin_user set username = :username ,email = :email ,status=:status,groupId=:groupId,phone=:phone,truename=:truename where id=:id");
if (isset($parameter_a['password']) && $parameter_a['password'] != "") {
$prepare_re = $db->prepare("update sk_admin_user set username = ?,password = ?,email= ?,status= ?,groupId= ?,phone= ?,truename=? where id=?");
$prepare_re->bindParam(1, $parameter_a['username'], PDO::PARAM_STR);
$prepare_re->bindParam(2, md5($parameter_a['password']), PDO::PARAM_STR);
$prepare_re->bindParam(3, $parameter_a['email'], PDO::PARAM_STR);
$prepare_re->bindParam(4, $parameter_a['status'], PDO::PARAM_STR);
$prepare_re->bindParam(5, $parameter_a['groupId'], PDO::PARAM_INT);
$prepare_re->bindParam(6, $parameter_a['phone'], PDO::PARAM_STR);
$prepare_re->bindParam(7, $parameter_a['truename'], PDO::PARAM_STR);
$prepare_re->bindParam(8, $parameter_a['id'], PDO::PARAM_STR);
} else {
$prepare_re = $db->prepare("update sk_admin_user set username = :username ,email = :email ,status= :status ,groupId= :groupId,phone= :phone,truename= :truename where id= :id");
$prepare_re->bindParam(":username", $parameter_a['username'], PDO::PARAM_STR);
$prepare_re->bindParam(":email", $parameter_a['email'], PDO::PARAM_STR);
$prepare_re->bindParam(":status", $parameter_a['status'], PDO::PARAM_STR);
$prepare_re->bindParam(":groupId", $parameter_a['groupId'], PDO::PARAM_INT);
$prepare_re->bindParam(":phone", $parameter_a['phone'], PDO::PARAM_STR);
$prepare_re->bindParam(":truename", $parameter_a['truename'], PDO::PARAM_STR);
$prepare_re->bindParam(":id", $parameter_a['id'], PDO::PARAM_STR);
}
$result = $prepare_re->execute();
return $result;
}