本文整理汇总了PHP中DB::prepare方法的典型用法代码示例。如果您正苦于以下问题:PHP DB::prepare方法的具体用法?PHP DB::prepare怎么用?PHP DB::prepare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DB
的用法示例。
在下文中一共展示了DB::prepare方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addPoint
private function addPoint()
{
$user = new User($this->getData());
if ($this->get("group_id") == self::$CLOSED_GROUP) {
$timeout = self::$CLOSED_GROUP_TIMEOUT;
} else {
$timeout = self::$OPEN_GROUP_TIMEOUT;
}
if ($user->isReadOnly()) {
$this->noRightsError();
} else {
if (time() - $user->getLastCreate()->getTimeStamp() < $timeout && !$user->isModerator()) {
$this->timeOutError(round((time() - $user->getLastCreate()->getTimeStamp()) / 60));
} else {
$userId = $this->get('userid');
$db = new DB();
$query = 'INSERT INTO mototimes_events (userid, lat, lng, alignment, transport, text) VALUES(?,?,?,?,?,?)';
$stmt = $db->prepare($query);
$stmt->bind_param('iddiis', $userId, $this->get('lat'), $this->get('lng'), $this->get('alignment'), $this->get('transport'), $this->get('text'));
$stmt->execute();
if ($stmt->errno != 0) {
$this->unknownError();
} else {
$query = 'UPDATE mototimes_users SET last_create = NOW() WHERE id_vk=?';
$stmt = $db->prepare($query);
$stmt->bind_param('i', $userId);
$stmt->execute();
$result = array('response' => 'ok');
$this->setResult($result);
}
}
}
}
示例2: delete
public function delete($id)
{
$sql = "DELETE FROM cadastro_funcionario WHERE id = :id";
$stmt = DB::prepare($sql);
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
return $stmt->execute();
}
示例3: makeRelation
protected function makeRelation($concepto, $parent)
{
if ($this->sthExistsRel == null) {
$query = "SELECT count(*) as count FROM relaciones_maestros WHERE id_inf = ? AND id_sup = ? ";
$this->sthExistsRel = DB::prepare($query);
}
$objCount = DB::executeFetch($this->sthExistsRel, array($concepto->id, $parent->id));
if ($objCount->count == 1) {
// ya existe la relación no se agrega.
return false;
}
if ($this->sthInsertRel == null) {
$query = "INSERT INTO relaciones_maestros (id_sup,id_inf,cantidad,factor,custom_nombre) values (?,?,?,?,?) ";
$this->sthInsertRel = DB::prepare($query);
}
$params = array();
$params[] = $parent->id;
$params[] = $concepto->id;
$params[] = $concepto->cantidad;
$params[] = $concepto->factor;
$params[] = isset($concepto->custom_nombre) ? $concepto->custom_nombre : '';
$this->sthInsertRel->execute($params);
//echo 'se creo relacion '. $concepto->id . ' ---> '. $parent->id .'\n<br/>' ;
return true;
}
示例4: get
public function get($ID)
{
$q = DB::prepare('SELECT * FROM MeCommentMockComment NATURAL JOIN Comment WHERE Comment.ID=:ID');
$q->execute(array(':ID' => $ID));
return self::fetch($q->fetch(), 'MeCommentMockComment');
}
示例5: get
public function get($name)
{
$q = DB::prepare('SELECT * FROM Bar WHERE ID=:ID');
$q->execute(array(':ID' => $name));
return self::fetch($q->fetch(), 'Bar');
}
示例6: get
public function get($username)
{
$q = DB::prepare('SELECT * FROM UserProfile WHERE username=:username');
$q->execute(array(':username' => $username));
return self::fetch($q->fetch(), 'UserProfile');
}
示例7: writeTags
/**
* Write out the tags for a specific resource.
*
* @param int $resource_id The story we are tagging.
* @param int $channel_id The channel id for the story we are tagging
* @param array $tags An array of tags.
*
* @TODO: Move this to a tagger class that uses Content_Tagger
* @return boolean
* @throws Jonah_Exception
*/
public function writeTags($resource_id, $channel_id, $tags)
{
global $conf;
// First, make sure all tag names exist in the DB.
$tagkeys = array();
$insert = $this->_db->prepare('INSERT INTO jonah_tags (tag_id, tag_name) VALUES(?, ?)');
$query = $this->_db->prepare('SELECT tag_id FROM jonah_tags WHERE tag_name = ?');
foreach ($tags as $tag) {
$tag = Horde_String::lower(trim($tag));
$results = $this->_db->execute($query, $this->_db->escapeSimple($tag));
if ($results instanceof PEAR_Error) {
throw new Jonah_Exception($results);
} elseif ($results->numRows() == 0) {
$id = $this->_db->nextId('jonah_tags');
$result = $this->_db->execute($insert, array($id, $tag));
$tagkeys[] = $id;
} else {
$row = $results->fetchRow(DB_FETCHMODE_ASSOC);
$tagkeys[] = $row['tag_id'];
}
}
// Free our resources.
$this->_db->freePrepared($insert, true);
$this->_db->freePrepared($query, true);
$sql = 'DELETE FROM jonah_stories_tags WHERE story_id = ' . (int) $resource_id;
$query = $this->_db->prepare('INSERT INTO jonah_stories_tags (story_id, channel_id, tag_id) VALUES(?, ?, ?)');
Horde::log('SQL query by Jonah_Driver_sql::writeTags: ' . $sql, 'DEBUG');
$this->_db->query($sql);
foreach ($tagkeys as $key) {
$this->_db->execute($query, array($resource_id, $channel_id, $key));
}
$this->_db->freePrepared($query, true);
/* @TODO We should clear at least any of our cached counts */
return true;
}
示例8: indexAction
public function indexAction()
{
//get the aff_camapaign_id
$mysql['use_pixel_payout'] = 0;
//see if it has the cookie in the campaign id, then the general match, then do whatever we can to grab SOMETHING to tie this lead to
if ($_COOKIE['btclickid']) {
$click_pid = $_COOKIE['btclickid'];
} else {
//ok grab the last click from this ip_id
$mysql['ip_address'] = DB::quote($_SERVER['REMOTE_ADDR']);
$daysago = time() - 2592000;
// 30 days ago
$click_sql1 = "\tSELECT \tbt_s_clicks.click_id\n\t\t\t\t\t\t\tFROM \t\tbt_s_clicks\n\t\t\t\t\t\t\tLEFT JOIN\tbt_s_clicks_advanced USING (click_id)\n\t\t\t\t\t\t\tLEFT JOIN \tbt_s_ips USING (ip_id)\n\t\t\t\t\t\t\tWHERE \tbt_s_ips.ip_address='" . $mysql['ip_address'] . "'\n\t\t\t\t\t\t\tAND\t\tbt_s_clicks.time >= '" . $daysago . "'\n\t\t\t\t\t\t\tORDER BY \tbt_s_clicks.click_id DESC\n\t\t\t\t\t\t\tLIMIT \t\t1";
$click_row1 = DB::getRow($click_sql1);
$click_pid = base_convert($click_row1['click_id'], 10, 36);
$mysql['ad_account_id'] = DB::quote($click_row1['ad_account_id']);
}
$click = ClickModel::model()->getRow(array('conditions' => array('click_id' => base_convert($click_pid, 36, 10))));
if (!$click) {
BTApp::end();
}
if ($click->get('ad_account_id')) {
if (getArrayVar($_GET, 'amount') && is_numeric($_GET['amount'])) {
$mysql['use_pixel_payout'] = 1;
}
if ($mysql['use_pixel_payout'] == 1) {
$click->convert(0, $_GET['amount']);
} else {
$click->convert();
}
if ($click->campaign->option('pixel_type')->value) {
$sql = "select v1.var_value as v1, v2.var_value as v2, v3.var_value as v3, v4.var_value as v4 from bt_s_clicks_advanced adv\n\t\t\t\t\tleft join bt_s_variables v1 on (v1.var_id=adv.v1_id)\n\t\t\t\t\tleft join bt_s_variables v2 on (v2.var_id=adv.v2_id)\n\t\t\t\t\tleft join bt_s_variables v3 on (v3.var_id=adv.v3_id)\n\t\t\t\t\tleft join bt_s_variables v4 on (v4.var_id=adv.v4_id)\n\t\t\t\t\twhere adv.click_id=?";
$st = DB::prepare($sql);
$st->execute(array($click->id()));
$row = $st->fetch();
$data['v1'] = $row['v1'];
$data['v2'] = $row['v2'];
$data['v3'] = $row['v3'];
$data['v4'] = $row['v4'];
$data['clickid'] = $click->id();
$data['keyword'] = '';
$data['amount'] = $click->payout;
$code = replaceTrackerPlaceholders($click->campaign->option('pixel_code')->value, $data);
$code = str_replace('[[amount]]', $data['amount'], $code);
switch ($click->campaign->option('pixel_type')->value) {
case 1:
case 2:
case 3:
echo $code;
break;
case 4:
$ch = curl_init($code);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 Postback-Bot v1.0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
break;
}
}
}
}
示例9: createPGPKey
public static function createPGPKey($username, $password)
{
// Can't create a pgp key without a name or a password.
// Also, if they shouldn't have a whitespace in their name but if they do somehow it could be an exploit.
if (empty($username) || empty($password)) {
return false;
} elseif (preg_match('/(\\s|\\n|\\r|\\/|\\.)/', $username) || preg_match('/\\s\\n\\r/', $password)) {
trigger_error("{$username} attempted exploit! - PGP Key creation");
return false;
}
// Create batch script for user.
// RSA Keys
// 2048 bit
file_put_contents("/tmp/{$username}", "Key-Type: default\n\t\t\tSubkey-Type: default\n\t\t\tName-Real: {$username}\n\t\t\tName-Comment: generated key for securechatty\n\t\t\tName-Email: noreply@securechatty.com\n\t\t\tExpire-Date: 0\n\t\t\tPassphrase: {$password}\n\t\t\t%pubring /tmp/{$username}.pub\n\t\t\t%secring /tmp/{$username}.sec\n\t\t\t%commit");
// Create the keys
$file = escapeshellarg('/tmp/' . $username);
exec("gpg2 --gen-key --batch {$file}");
// Retrieve the keys
$publickey = file_get_contents("/tmp/{$username}.pub");
$privatekey = file_get_contents("/tmp/{$username}.sec");
// Remove all unneeded files.
unlink("/tmp/{$username}");
unlink("/tmp/{$username}.pub");
unlink("/tmp/{$username}.sec");
if (empty($publickey) || empty($privatekey)) {
trigger_error("Key generation failed for {$username}!");
return false;
}
$db = new DB();
$update = $db->prepare("UPDATE users SET\n\t\t\t\tpublickey = :publickey,\n\t\t\t\tprivatekey = :privatekey\n\t\t\t WHERE username = :username");
$update->execute(array(':publickey' => $publickey, ':privatekey' => $privatekey, ':username' => $username));
return true;
}
示例10: getDBUsage
function getDBUsage($domainID)
{
$dbSize = 0;
// get database information for given domain
$sql_param = array(':domain_id' => $domainID);
$sql_query = "\n\t\t\tSELECT\n\t\t\t\tsqld_id, sqld_name\n\t\t\tFROM\n\t\t\t\tsql_database\n\t\t\tWHERE\n\t\t\t\tdomain_id = :domain_id\n\t\t";
DB::prepare($sql_query);
$sqlData = DB::execute($sql_param);
// get usage for each database
$sql_query = '
SELECT
sum(data_length + index_length) size
FROM
information_schema.tables
WHERE
table_schema = :table_schema
GROUP BY
table_schema
';
while ($row = $sqlData->fetch()) {
$sql_param = array(':table_schema' => $row['sqld_name']);
DB::prepare($sql_query);
$sqlSize = DB::execute($sql_param, true);
$dbSize += $sqlSize[0];
}
return $dbSize;
}
示例11: delete
public function delete($id)
{
$qry = "DELETE FROM {$this->tabela} WHERE id = :id";
$stm = DB::prepare($qry);
$stm->bindParam(':id', $id, PDO::PARAM_INT);
return $stm->execute();
}
示例12: menu_delete_db
function menu_delete_db()
{
$s = DB::prepare('DROP TABLE IF EXISTS MenuEntry');
$s->execute();
$s = DB::prepare('DROP TABLE IF EXISTS Menu');
$s->execute();
}
示例13: findFree
private function findFree()
{
$args = array();
$wheres = array();
foreach ($this->_fixed as $fix)
{
$fixDB = $fix.'_db';
$args[':'.$fix] = $this->_object->$fixDB;
$wheres[] = $fix.'=:'.$fix;
}
$wheres[] = $this->_normalized .'=:_a';
$q = DB::prepare('SELECT * FROM ' . $this->_class . ' WHERE '. implode(' AND ', $wheres));
$f = $this->_toNormalize;
$base = $this->normalize($this->_object->$f);
$i = 0;
$full = $base;
$args[':_a'] = $full;
$q->execute($args);
while ($q->fetch())
{
$i++;
$full = $base.$i;
$args[':_a'] = $full;
$q->execute($args);
}
return $full;
}
示例14: check_login
function check_login()
{
global $db, $mem;
if (defined('MEM') && MEM == True) {
$mem = new Memcached('moyoj');
$mem->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE, true);
if (!count($mem->getServerList())) {
$mem->addServer(MEM_HOST, MEM_PORT);
}
}
$db = new DB();
$db->init(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$db->connect();
$admin_info = mo_read_cache('mo-admin-' . $_SESSION['aid']);
if (!$admin_info) {
$sql = 'SELECT `id`, `username`, `password`, `nickname`, `role` FROM `mo_admin` WHERE `id` = ? AND `role` > 0';
$db->prepare($sql);
$db->bind('i', $_SESSION['aid']);
$result = $db->execute();
if (!$result || $result[0]['password'] != $_SESSION['admin_password']) {
unset($_SESSION['aid']);
header("Location: login.php");
exit(0);
}
mo_write_cache('mo-admin-' . $_SESSION['aid'], $result[0]);
}
$mo_settings = array();
mo_load_settings();
if (!isset($active)) {
$active = '';
}
}
示例15: CreatePDNSPass
/**
* @return mixed
*/
public static function CreatePDNSPass()
{
System_Daemon::debug('Starting "DaemonConfigDNS::createPDNSPass" subprocess.');
$xml = simplexml_load_file(DaemonConfig::$cfg->{'CONF_DIR'} . '/tpl/EasySCP_Config_DNS.xml');
System_Daemon::debug('Building the new pdns config file');
$xml->{'PDNS_USER'} = 'powerdns';
$xml->{'PDNS_PASS'} = DB::encrypt_data(DaemonCommon::generatePassword(18));
$xml->{'HOSTNAME'} = idn_to_ascii(DaemonConfig::$cfg->{'DATABASE_HOST'});
$handle = fopen(DaemonConfig::$cfg->{'CONF_DIR'} . '/EasySCP_Config_DNS.xml', "wb");
fwrite($handle, $xml->asXML());
fclose($handle);
DaemonCommon::systemSetFilePermissions(DaemonConfig::$cfg->{'CONF_DIR'} . '/EasySCP_Config_DNS.xml', DaemonConfig::$cfg->{'ROOT_USER'}, DaemonConfig::$cfg->{'ROOT_GROUP'}, 0640);
// Create/Update Powerdns control user account if needed
System_Daemon::debug('Adding the PowerDNS control user');
$sql_param = array(':PDNS_USER' => $xml->{'PDNS_USER'}, ':PDNS_PASS' => DB::decrypt_data($xml->{'PDNS_PASS'}), ':HOSTNAME' => $xml->{'HOSTNAME'});
$sql_query = "\n\t\t\tGRANT ALL PRIVILEGES ON powerdns.* TO :PDNS_USER@:HOSTNAME IDENTIFIED BY :PDNS_PASS;\n\t\t\tFLUSH PRIVILEGES;\n\t\t";
DB::prepare($sql_query);
DB::execute($sql_param)->closeCursor();
$sql_param = array(':DATABASE_USER' => DaemonConfig::$cfg->DATABASE_USER, ':DATABASE_HOST' => idn_to_ascii(DaemonConfig::$cfg->{'DATABASE_HOST'}));
$sql_query = "\n\t\t\tGRANT ALL PRIVILEGES ON powerdns.* TO :DATABASE_USER@:DATABASE_HOST;\n\t\t\tFLUSH PRIVILEGES;\n\t\t";
DB::prepare($sql_query);
DB::execute($sql_param)->closeCursor();
System_Daemon::debug('Finished "DaemonConfigDNS::createPDNSPass" subprocess.');
return true;
}