本文整理汇总了PHP中JDatabaseDriver::execute方法的典型用法代码示例。如果您正苦于以下问题:PHP JDatabaseDriver::execute方法的具体用法?PHP JDatabaseDriver::execute怎么用?PHP JDatabaseDriver::execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JDatabaseDriver
的用法示例。
在下文中一共展示了JDatabaseDriver::execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: remove
/**
* Remove an extra image from database and file system.
*
* <code>
* $imageId = 1;
* $imagesFolder = "/.../folder";
*
* $image = new CrowdFundingImageRemoverExtra(JFactory::getDbo(), $image, $imagesFolder);
* $image->remove();
* </code>
*/
public function remove()
{
// Get the image
$query = $this->db->getQuery(true);
$query->select("a.image, a.thumb")->from($this->db->quoteName("#__crowdf_images", "a"))->where("a.id = " . (int) $this->imageId);
$this->db->setQuery($query);
$row = $this->db->loadObject();
if (!empty($row)) {
// Remove the image from the filesystem
$file = JPath::clean($this->imagesFolder . DIRECTORY_SEPARATOR . $row->image);
if (JFile::exists($file)) {
JFile::delete($file);
}
// Remove the thumbnail from the filesystem
$file = JPath::clean($this->imagesFolder . DIRECTORY_SEPARATOR . $row->thumb);
if (JFile::exists($file)) {
JFile::delete($file);
}
// Delete the record
$query = $this->db->getQuery(true);
$query->delete($this->db->quoteName("#__crowdf_images"))->where($this->db->quoteName("id") . " = " . (int) $this->imageId);
$this->db->setQuery($query);
$this->db->execute();
}
}
示例2: onUserAfterDelete
/**
* Remove all sessions for the user name
*
* Method is called after user data is deleted from the database
*
* @param array $user Holds the user data
* @param boolean $success True if user was successfully stored in the database
* @param string $msg Message
*
* @return boolean
*
* @since 1.6
*/
public function onUserAfterDelete($user, $success, $msg)
{
$userId = Joomla\Utilities\ArrayHelper::getValue($user, 'id', 0, 'int');
if (!$success or !$userId) {
return false;
}
// Remove profile images.
$profile = new Socialcommunity\Profile\Profile($this->db);
$profile->load(array('user_id' => $userId));
if ($profile->getId()) {
// Remove profile record.
$query = $this->db->getQuery(true);
$query->delete($this->db->quoteName('#__itpsc_profiles'))->where($this->db->quoteName('user_id') . '=' . (int) $userId);
$this->db->setQuery($query);
$this->db->execute();
// Remove profile images.
$params = JComponentHelper::getParams('com_socialcommunity');
/** @var $params Joomla\Registry\Registry */
jimport('Prism.libs.init');
$filesystemHelper = new Prism\Filesystem\Helper($params);
$mediaFolder = $filesystemHelper->getMediaFolder($userId);
$filesystem = $filesystemHelper->getFilesystem();
$profile->removeImages($filesystem, $mediaFolder);
}
return true;
}
示例3: query
/**
* Execute the query
*
* @param string $sql The query (optional, it will use the setQuery one otherwise)
* @return \mysqli_result|\resource|boolean A database resource if successful, FALSE if not.
*
* @throws \RuntimeException
*/
public function query($sql = null)
{
if ($sql !== null) {
$this->setQuery($sql);
}
return $this->_db->execute();
}
示例4: delete
/**
* Method to delete a row from the database table by primary key value.
*
* @param int|array $pk An optional primary key value (or array of key=>value pairs) to delete. If not set the instance property value is used.
*
* @return boolean True on success.
*
* @link http://docs.joomla.org/JTable/delete
* @throws UnexpectedValueException
*/
public function delete($pk = null)
{
$k = $this->_tbl_key;
$pk = (is_null($pk)) ? $this->{$k} : $pk;
// If no primary key is given, return false.
if ($pk === null)
{
throw new UnexpectedValueException('Null primary key not allowed.');
}
// Turn pk into array.
if (!is_array($pk))
{
$pk = array($k => (int) $pk);
}
// Delete the row by primary key.
$query = $this->_db->getQuery(true);
$query->delete();
$query->from($this->_tbl);
foreach ($pk as $key=>$value)
{
$query->where($key . ' = ' . $this->_db->quote($value));
}
$this->_db->setQuery($query);
// Delete items.
$this->_db->execute();
return true;
}
示例5: hit
/**
* Register a hit on a record
*
* @param integer $oid The primary key value of the record
* @param boolean $log Should I log the hit?
*
* @return boolean True on success
*/
public function hit($oid = null, $log = false)
{
if (!$this->onBeforeHit($oid, $log)) {
return false;
}
// If there is no hits field, just return true.
$hits_field = $this->getColumnAlias('hits');
if (!in_array($hits_field, $this->getKnownFields())) {
return true;
}
$k = $this->_tbl_key;
$pk = is_null($oid) ? $this->{$k} : $oid;
// If no primary key is given, return false.
if ($pk === null) {
$result = false;
} else {
// Check the row in by primary key.
$query = $this->_db->getQuery(true);
$query->update($this->_tbl);
$query->set($this->_db->qn($hits_field) . ' = (' . $this->_db->qn($hits_field) . ' + 1)');
$query->where($this->_tbl_key . ' = ' . $this->_db->q($pk));
$this->_db->setQuery($query);
$this->_db->execute();
// Set table values in the object.
$this->hits++;
$result = true;
}
if ($result) {
$result = $this->onAfterHit($oid);
}
return $result;
}
示例6: storeVotes
protected function storeVotes()
{
$query = $this->db->getQuery(true);
$query->update($this->db->quoteName("#__uideas_items"))->set($this->db->quoteName("votes") . "=" . (int) $this->votes)->where($this->db->quoteName("id") . "=" . (int) $this->id);
$this->db->setQuery($query);
$this->db->execute();
}
示例7: updateObject
protected function updateObject()
{
$query = $this->db->getQuery(true);
$query->update($this->db->quoteName("#__vc_transactions"))->set($this->db->quoteName("units") . "=" . $this->db->quote($this->units))->set($this->db->quoteName("txn_id") . "=" . $this->db->quote($this->txn_id))->set($this->db->quoteName("txn_amount") . "=" . $this->db->quote($this->txn_amount))->set($this->db->quoteName("txn_currency") . "=" . $this->db->quote($this->txn_currency))->set($this->db->quoteName("txn_status") . "=" . $this->db->quote($this->txn_status))->set($this->db->quoteName("txn_date") . "=" . $this->db->quote($this->txn_date))->set($this->db->quoteName("service_provider") . "=" . $this->db->quote($this->service_provider))->set($this->db->quoteName("currency_id") . "=" . $this->db->quote($this->currency_id))->set($this->db->quoteName("sender_id") . "=" . $this->db->quote($this->sender_id))->set($this->db->quoteName("receiver_id") . "=" . $this->db->quote($this->receiver_id))->where($this->db->quoteName("id") . "=" . (int) $this->id);
$this->db->setQuery($query);
$this->db->execute();
}
示例8: delete
/**
* Delete a record
*
* @param integer $oid The primary key value of the item to delete
*
* @throws UnexpectedValueException
*
* @return boolean True on success
*/
public function delete($oid = null)
{
if ($oid) {
$this->load($oid);
}
$k = $this->_tbl_key;
$pk = !$oid ? $this->{$k} : $oid;
// If no primary key is given, return false.
if (!$pk) {
throw new UnexpectedValueException('Null primary key not allowed.');
}
// Execute the logic only if I have a primary key, otherwise I could have weird results
if (!$this->onBeforeDelete($oid)) {
return false;
}
// Delete the row by primary key.
$query = $this->_db->getQuery(true);
$query->delete();
$query->from($this->_tbl);
$query->where($this->_tbl_key . ' = ' . $this->_db->q($pk));
$this->_db->setQuery($query);
$this->_db->execute();
$result = $this->onAfterDelete($oid);
return $result;
}
示例9: hit
/**
* Method to increment the hits for a row if the necessary property/field exists.
*
* @return bool True on success.
*
* @internal param mixed $pk An optional primary key value to increment. If not set the instance property value is used.
*
* @since K4.0
*/
public function hit()
{
$pk = null;
// If there is no hits field, just return true.
if (!property_exists($this, 'hits'))
{
return true;
}
$k= static::$tbl_keys;
$pk = (is_null($pk)) ? $this->$k : $pk;
// If no primary key is given, return false.
if ($pk === null)
{
return false;
}
// Check the row in by primary key.
$query = static::$db->getQuery(true);
$query->update(static::$tbl);
$query->set(static::$db->quoteName('hits') . ' = (' . static::$db->quoteName('hits') . ' + 1)');
$query->where(static::$tbl_key . ' = ' . static::$db->quote($pk));
static::$db->setQuery($query);
static::$db->execute();
// Set table values in the object.
$this->hits++;
return true;
}
示例10: storeInDatabase
/**
* Stores the login data into the database
*
* @param array $data Array holding data to be stored.
*
* @return bool
* @since 1.0
*/
public function storeInDatabase($data)
{
$query = $this->db->getQuery(true);
$columns = array('userid', 'username', 'ip', 'timestamp');
$values = $this->db->quote(array($data['userid'], $data['username'], $data['ip'], $data['timestamp']));
$query->insert($this->db->quoteName('#__userlogin_tracking'))->columns($this->db->quoteName($columns))->values(implode(',', $values));
$this->db->setQuery($query);
try {
$this->db->execute();
} catch (Exception $e) {
throw $e;
// Do nothing
return false;
}
return true;
}
示例11: unmap
/**
* Unmap two contnet
*
* @param string $content_id1 The id of content 1
* @param string $content_id2 The id of content 2
*
* @return void
*
* @since 1.0
*/
public function unmap($content_id1, $content_id2 = null)
{
$contentType = $this->state->get('content.type');
// Check if the content type is set.
if (empty($contentType)) {
// Get the content type for the id.
if (!is_null($content_id2)) {
$results = $this->getTypes($content_id2);
// Assert that the content type was found.
if (empty($results[$content_id2])) {
throw new UnexpectedValueException(sprintf('%s->getItem() could not find the content type for item %s.', get_class($this), $content_id2));
}
// Set the content type alias.
$contentType = $results[$content_id2]->type;
} else {
throw new UnexpectedValueException(sprintf('%s->getItem() could not find the content type for item %s.', get_class($this), $content_id2));
}
}
$query = $this->db->getQuery(true);
$query->clear();
$query->delete();
$query->from($this->db->quoteName('#__content_' . $contentType . '_map'));
$query->where($this->db->quoteName('content_id') . '=' . $content_id1);
if (!is_null($content_id2)) {
$query->where($this->db->quoteName('tag_id') . '=' . $content_id2);
}
$this->db->setQuery($query);
try {
$this->db->execute();
} catch (Exception $er) {
return false;
}
return true;
}
示例12: updateAmount
/**
* Update the amount of the account.
*
* <code>
* // Get user account by account ID
* $accountId = 1;
*
* $account = new VirtualCurrencyAccount();
* $account->setDb(JFactory::getDbo());
* $account->load($accountId);
*
* // Increase the amount and store the new value.
* $account->increaseAmount(50);
* $account->updateAmount();
* </code>
*/
public function updateAmount()
{
$query = $this->db->getQuery(true);
$query->update($this->db->quoteName("#__vc_accounts"))->set($this->db->quoteName("amount") . "=" . $this->db->quote($this->amount))->where($this->db->quoteName("id") . "=" . (int) $this->id);
$this->db->setQuery($query);
$this->db->execute();
}
示例13: createUser
/**
* Create user record in database.
*
* <code>
* $data = array(
* "id" => 1,
* "name" => "John Dow",
* "state" => 1,
* );
*
* $user = new IdentityProofUser(JFactory::getDbo());
* $user->bind($data);
* $user->createUser();
* </code>
*/
public function createUser()
{
$query = $this->db->getQuery(true);
$query->insert($this->db->quoteName("#__identityproof_users"))->set($this->db->quoteName("id") . "=" . $this->db->quote($this->id))->set($this->db->quoteName("state") . "=" . $this->db->quote($this->state));
$this->db->setQuery($query);
$this->db->execute();
}
示例14: mergeStructure
/**
* Merges the incoming structure definition with the existing structure.
*
* @return void
*
* @note Currently only supports XML format.
* @since 13.1
* @throws RuntimeException on error.
*/
public function mergeStructure()
{
$prefix = $this->db->getPrefix();
$tables = $this->db->getTableList();
if ($this->from instanceof SimpleXMLElement) {
$xml = $this->from;
} else {
$xml = new SimpleXMLElement($this->from);
}
// Get all the table definitions.
$xmlTables = $xml->xpath('database/table_structure');
foreach ($xmlTables as $table) {
// Convert the magic prefix into the real table name.
$tableName = (string) $table['name'];
$tableName = preg_replace('|^#__|', $prefix, $tableName);
if (in_array($tableName, $tables)) {
// The table already exists. Now check if there is any difference.
if ($queries = $this->getAlterTableSql($xml->database->table_structure)) {
// Run the queries to upgrade the data structure.
foreach ($queries as $query) {
$this->db->setQuery((string) $query);
$this->db->execute();
}
}
} else {
// This is a new table.
$sql = $this->xmlToCreate($table);
$this->db->setQuery((string) $sql);
$this->db->execute();
}
}
}
示例15: updateFunds
/**
* Update project funds record.
*
* <code>
* $projectId = 1;
* $finds = 50;
*
* $project = new CrowdFundingProject(JFactory::getDbo());
* $project->load($projectId);
* $project->addFunds($finds);
* $project->updateFunds();
* </code>
*/
public function updateFunds()
{
$query = $this->db->getQuery(true);
$query->update($this->db->quoteName("#__crowdf_projects"))->set($this->db->quoteName("funded") . "=" . $this->db->quote($this->funded))->where($this->db->quoteName("id") . "=" . $this->db->quote($this->id));
$this->db->setQuery($query);
$this->db->execute();
}