本文整理汇总了PHP中update_sql函数的典型用法代码示例。如果您正苦于以下问题:PHP update_sql函数的具体用法?PHP update_sql怎么用?PHP update_sql使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了update_sql函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: hook_update_N
/**
* Perform a single update. For each patch which requires a database change add
* a new hook_update_N() which will be called by update.php.
*
* The database updates are numbered sequentially according to the version of Drupal you are compatible with.
*
* Schema updates should adhere to the Schema API:
* @link http://drupal.org/node/150215 http://drupal.org/node/150215 @endlink
*
* Database updates consist of 3 parts:
* - 1 digit for Drupal core compatibility
* - 1 digit for your module's major release version (e.g. is this the 5.x-1.* (1) or 5.x-2.* (2) series of your module?)
* - 2 digits for sequential counting starting with 00
*
* The 2nd digit should be 0 for initial porting of your module to a new Drupal
* core API.
*
* Examples:
* - mymodule_update_5200()
* - This is the first update to get the database ready to run mymodule 5.x-2.*.
* - mymodule_update_6000()
* - This is the required update for mymodule to run with Drupal core API 6.x.
* - mymodule_update_6100()
* - This is the first update to get the database ready to run mymodule 6.x-1.*.
* - mymodule_update_6200()
* - This is the first update to get the database ready to run mymodule 6.x-2.*.
* Users can directly update from 5.x-2.* to 6.x-2.* and they get all 60XX
* and 62XX updates, but not 61XX updates, because those reside in the
* 6.x-1.x branch only.
*
* A good rule of thumb is to remove updates older than two major releases of
* Drupal. See hook_update_last_removed() to notify Drupal about the removals.
*
* Never renumber update functions.
*
* Further information about releases and release numbers:
* - @link http://drupal.org/handbook/version-info http://drupal.org/handbook/version-info @endlink
* - @link http://drupal.org/node/93999 http://drupal.org/node/93999 @endlink (Overview of contributions branches and tags)
* - @link http://drupal.org/handbook/cvs/releases http://drupal.org/handbook/cvs/releases @endlink
*
* Implementations of this hook should be placed in a mymodule.install file in
* the same directory as mymodule.module. Drupal core's updates are implemented
* using the system module as a name and stored in database/updates.inc.
*
* If your update task is potentially time-consuming, you'll need to implement a
* multipass update to avoid PHP timeouts. Multipass updates use the $sandbox
* parameter provided by the batch API (normally, $context['sandbox']) to store
* information between successive calls, and the $ret['#finished'] return value
* to provide feedback regarding completion level.
*
* See the batch operations page for more information on how to use the batch API:
* @link http://drupal.org/node/146843 http://drupal.org/node/146843 @endlink
*
* @return An array with the results of the calls to update_sql(). An upate
* function can force the current and all later updates for this
* module to abort by returning a $ret array with an element like:
* $ret['#abort'] = array('success' => FALSE, 'query' => 'What went wrong');
* The schema version will not be updated in this case, and all the
* aborted updates will continue to appear on update.php as updates that
* have not yet been run. Multipass update functions will also want to pass
* back the $ret['#finished'] variable to inform the batch API of progress.
*/
function hook_update_N(&$sandbox = NULL)
{
// For most updates, the following is sufficient.
$ret = array();
db_add_field($ret, 'mytable1', 'newcol', array('type' => 'int', 'not null' => TRUE, 'description' => 'My new integer column.'));
return $ret;
// However, for more complex operations that may take a long time,
// you may hook into Batch API as in the following example.
$ret = array();
// Update 3 users at a time to have an exclamation point after their names.
// (They're really happy that we can do batch API in this hook!)
if (!isset($sandbox['progress'])) {
$sandbox['progress'] = 0;
$sandbox['current_uid'] = 0;
// We'll -1 to disregard the uid 0...
$sandbox['max'] = db_query('SELECT COUNT(DISTINCT uid) FROM {users}')->fetchField() - 1;
}
db_select('users', 'u')->fields('u', array('uid', 'name'))->condition('uid', $sandbox['current_uid'], '>')->range(0, 3)->orderBy('uid', 'ASC')->execute();
foreach ($users as $user) {
$user->name .= '!';
$ret[] = update_sql("UPDATE {users} SET name = '{$user->name}' WHERE uid = {$user->uid}");
$sandbox['progress']++;
$sandbox['current_uid'] = $user->uid;
}
$ret['#finished'] = empty($sandbox['max']) ? 1 : $sandbox['progress'] / $sandbox['max'];
return $ret;
}
开发者ID:nicklewisatx,项目名称:drupal,代码行数:89,代码来源:system.api.php
示例2: update_fix_compatibility
/**
* Disable anything in the {system} table that is not compatible with the
* current version of Drupal core.
*/
function update_fix_compatibility()
{
$ret = array();
$incompatible = array();
$query = db_query("SELECT name, type, status FROM {system} WHERE status = 1 AND type IN ('module','theme')");
while ($result = db_fetch_object($query)) {
if (update_check_incompatibility($result->name, $result->type)) {
$incompatible[] = $result->name;
}
}
if (!empty($incompatible)) {
$ret[] = update_sql("UPDATE {system} SET status = 0 WHERE name IN ('" . implode("','", $incompatible) . "')");
}
return $ret;
}
开发者ID:veggieryan,项目名称:drupal,代码行数:19,代码来源:update.php
示例3: drupal_update_131
function drupal_update_131()
{
$ret = array();
$ret[] = update_sql("ALTER TABLE {locales_source} CHANGE location location varchar(255) NOT NULL default ''");
return $ret;
}
开发者ID:BackupTheBerlios,项目名称:astbill-svn,代码行数:6,代码来源:astbillupdatesvn.php
示例4: update_70
function update_70()
{
update_sql("ALTER TABLE {variable} CHANGE name name varchar(48) NOT NULL");
}
开发者ID:shjalayeri,项目名称:Blood-Money,代码行数:4,代码来源:update.php
示例5: fanli
function fanli($username, $fxje, $tgje, $order_code, $merchant_id)
{
if (JIFENOPEN == 1 && JIFENBL > 0) {
$jifen = round($fxje * JIFENBL);
if ($jifen > 0) {
$msg_tabao_jifen = $jifen . "积分!";
}
} else {
$jifen = 0;
}
$field_arr = array('money' => $fxje, 'jifen' => $jifen, 'dengji' => 1);
update_sql('user', $field_arr, "ddusername='{$username}'", 1);
//增加会员金额,积分和等级
//用户消息
$title = '您获得了新的商城交易返现!';
$trade_id = $order_code;
$msg_tabao = "您获得了新的交易返现," . $merchant_id . "商城订单号" . $order_code . "返现金额" . $fxje . '!' . $msg_tabao_jifen;
$filed_arr = array('title' => $title, 'content' => $msg_tabao, 'addtime' => date('Y-m-d H:i:s'), 'see' => 0, 'ddusername' => $ddusername, 'senduser' => '网站客服');
insert_one_sql("msg", $filed_arr);
//用户明细
$shijian = "商城交易返现";
$memo = $merchant_id . "交易号{$order_code}";
$filed_arr = array('ddusername' => $ddusername, 'shijian' => $shijian, 'addtime' => date('Y-m-d H:i:s'), 'je' => $fxje, 'jifen' => $jifen, 'memo' => $memo);
insert_one_sql("mingxi", $filed_arr);
//求推荐人
$tjrid = sel_sql("user", "tjr", "ddusername='{$ddusername}'");
if ($tjrid > 0) {
$tjrname = sel_sql("user", "ddusername", "Id='{$tjrid}'");
//增加推荐人佣金
$field_arr = array('money' => $tgje);
update_sql("user", $field_arr, "Id='{$tjrid}'", 1);
//用户消息
$title = '您获得了新的推广佣金!';
$msg_taobaotuiguang = "您获得了新的推广佣金" . $tgje;
$filed_arr = array('title' => $title, 'content' => $msg_taobaotuiguang, 'addtime' => date('Y-m-d H:i:s'), 'see' => 0, 'ddusername' => $tjrname, 'senduser' => '网站客服');
insert_one_sql("msg", $filed_arr);
//用户明细
$shijian = "推广佣金";
$memo = "交易人{$ddusername}";
$filed_arr = array('ddusername' => $tjrname, 'shijian' => $shijian, 'addtime' => date('Y-m-d H:i:s'), 'je' => $tgje, 'memo' => $memo);
insert_one_sql("mingxi", $filed_arr);
}
}
开发者ID:chenyongze,项目名称:januarybuy_develop,代码行数:43,代码来源:common.php
示例6: computeSimilarityDatabase
protected function computeSimilarityDatabase()
{
watchdog("recommender", "Computing similarity in database. Might take a long time. Please be patient.");
if ($this->fieldWeight === NULL) {
$count = "COUNT(*)";
// if no $fieldWeight is specified, just count the occurrences.
} else {
// otherwise, use the weight.
$count = "SUM((n1.{$this->fieldWeight}+n2.{$this->fieldWeight})/2)";
}
$sql = "INSERT INTO {recommender_similarity}(app_id, mouse1_id, mouse2_id, similarity, created)\n SELECT {$this->appId}, n1.{$this->fieldMouse}, n2.{$this->fieldMouse}, {$count}, {$this->created}\n FROM {{$this->tableName}} n1 INNER JOIN {{$this->tableName}} n2 ON n1.{$this->fieldCheese}=n2.{$this->fieldCheese}\n GROUP BY n1.{$this->fieldMouse}, n2.{$this->fieldMouse}";
update_sql($sql);
$this->purgeOutdatedRecords('similarity');
}
开发者ID:rmontero,项目名称:dla_ecommerce_site,代码行数:14,代码来源:Recommender.php
示例7: update_create_cache_tables
/**
* Create tables for the split cache.
*
* This is part of the Drupal 4.7.x to 5.x migration.
*/
function update_create_cache_tables()
{
// If cache_filter exists, update is not necessary
if (db_table_exists('cache_filter')) {
return;
}
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("CREATE TABLE {cache_filter} (\n cid varchar(255) NOT NULL default '',\n data longblob,\n expire int NOT NULL default '0',\n created int NOT NULL default '0',\n headers text,\n PRIMARY KEY (cid),\n INDEX expire (expire)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
$ret[] = update_sql("CREATE TABLE {cache_menu} (\n cid varchar(255) NOT NULL default '',\n data longblob,\n expire int NOT NULL default '0',\n created int NOT NULL default '0',\n headers text,\n PRIMARY KEY (cid),\n INDEX expire (expire)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
$ret[] = update_sql("CREATE TABLE {cache_page} (\n cid varchar(255) BINARY NOT NULL default '',\n data longblob,\n expire int NOT NULL default '0',\n created int NOT NULL default '0',\n headers text,\n PRIMARY KEY (cid),\n INDEX expire (expire)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
break;
case 'pgsql':
$ret[] = update_sql("CREATE TABLE {cache_filter} (\n cid varchar(255) NOT NULL default '',\n data bytea,\n expire int NOT NULL default '0',\n created int NOT NULL default '0',\n headers text,\n PRIMARY KEY (cid)\n )");
$ret[] = update_sql("CREATE TABLE {cache_menu} (\n cid varchar(255) NOT NULL default '',\n data bytea,\n expire int NOT NULL default '0',\n created int NOT NULL default '0',\n headers text,\n PRIMARY KEY (cid)\n )");
$ret[] = update_sql("CREATE TABLE {cache_page} (\n cid varchar(255) NOT NULL default '',\n data bytea,\n expire int NOT NULL default '0',\n created int NOT NULL default '0',\n headers text,\n PRIMARY KEY (cid)\n )");
$ret[] = update_sql("CREATE INDEX {cache_filter}_expire_idx ON {cache_filter} (expire)");
$ret[] = update_sql("CREATE INDEX {cache_menu}_expire_idx ON {cache_menu} (expire)");
$ret[] = update_sql("CREATE INDEX {cache_page}_expire_idx ON {cache_page} (expire)");
break;
}
return $ret;
}
开发者ID:naryga,项目名称:alm-familyfellowship-com,代码行数:30,代码来源:update.php
示例8: update_convert_table_utf8
/**
* Convert a single MySQL table to UTF-8.
*
* We change all text columns to their corresponding binary type,
* then back to text, but with a UTF-8 character set.
* See: http://dev.mysql.com/doc/refman/4.1/en/charset-conversion.html
*/
function update_convert_table_utf8($table)
{
$ret = array();
$types = array('char' => 'binary', 'varchar' => 'varbinary', 'tinytext' => 'tinyblob', 'text' => 'blob', 'mediumtext' => 'mediumblob', 'longtext' => 'longblob');
// Get next table in list
$convert_to_binary = array();
$convert_to_utf8 = array();
// Set table default charset
$ret[] = update_sql('ALTER TABLE {' . $table . '} DEFAULT CHARACTER SET utf8');
// Find out which columns need converting and build SQL statements
$result = db_query('SHOW FULL COLUMNS FROM {' . $table . '}');
while ($column = db_fetch_array($result)) {
list($type) = explode('(', $column['Type']);
if (isset($types[$type])) {
$names = 'CHANGE `' . $column['Field'] . '` `' . $column['Field'] . '` ';
$attributes = ' DEFAULT ' . ($column['Default'] == 'NULL' ? 'NULL ' : "'" . db_escape_string($column['Default']) . "' ") . ($column['Null'] == 'YES' ? 'NULL' : 'NOT NULL');
$convert_to_binary[] = $names . preg_replace('/' . $type . '/i', $types[$type], $column['Type']) . $attributes;
$convert_to_utf8[] = $names . $column['Type'] . ' CHARACTER SET utf8' . $attributes;
}
}
if (count($convert_to_binary)) {
// Convert text columns to binary
$ret[] = update_sql('ALTER TABLE {' . $table . '} ' . implode(', ', $convert_to_binary));
// Convert binary columns to UTF-8
$ret[] = update_sql('ALTER TABLE {' . $table . '} ' . implode(', ', $convert_to_utf8));
}
return $ret;
}
开发者ID:skellystarman,项目名称:drupaldev,代码行数:35,代码来源:update.php
示例9: hook_update_N
/**
* Perform a single update.
*
* For each patch which requires a database change add a new hook_update_N()
* which will be called by update.php. The database updates are numbered
* sequentially according to the version of Drupal you are compatible with.
*
* Schema updates should adhere to the Schema API: http://drupal.org/node/150215
*
* Database updates consist of 3 parts:
* - 1 digit for Drupal core compatibility
* - 1 digit for your module's major release version (e.g. is this the 5.x-1.* (1) or 5.x-2.* (2) series of your module?)
* - 2 digits for sequential counting starting with 00
*
* The 2nd digit should be 0 for initial porting of your module to a new Drupal
* core API.
*
* Examples:
* - mymodule_update_5200()
* - This is the first update to get the database ready to run mymodule 5.x-2.*.
* - mymodule_update_6000()
* - This is the required update for mymodule to run with Drupal core API 6.x.
* - mymodule_update_6100()
* - This is the first update to get the database ready to run mymodule 6.x-1.*.
* - mymodule_update_6200()
* - This is the first update to get the database ready to run mymodule 6.x-2.*.
* Users can directly update from 5.x-2.* to 6.x-2.* and they get all 60XX
* and 62XX updates, but not 61XX updates, because those reside in the
* 6.x-1.x branch only.
*
* A good rule of thumb is to remove updates older than two major releases of
* Drupal. See hook_update_last_removed() to notify Drupal about the removals.
*
* Never renumber update functions.
*
* Further information about releases and release numbers:
* - http://drupal.org/handbook/version-info
* - http://drupal.org/node/93999 (Overview of contributions branches and tags)
* - http://drupal.org/handbook/cvs/releases
*
* Implementations of this hook should be placed in a mymodule.install file in
* the same directory as mymodule.module. Drupal core's updates are implemented
* using the system module as a name and stored in database/updates.inc.
*
* @return An array with the results of the calls to update_sql(). An update
* function can force the current and all later updates for this
* module to abort by returning a $ret array with an element like:
* $ret['#abort'] = array('success' => FALSE, 'query' => 'What went wrong');
* The schema version will not be updated in this case, and all the
* aborted updates will continue to appear on update.php as updates that
* have not yet been run. Multipass update functions will also want to pass
* back the $ret['#finished'] variable to inform the batch API of progress.
*/
function hook_update_N(&$sandbox)
{
// For non-multipass updates, the signature can simply be;
// function hook_update_N() {
// For most updates, the following is sufficient.
$ret = array();
db_add_field($ret, 'mytable1', 'newcol', array('type' => 'int', 'not null' => TRUE));
return $ret;
// However, for more complex operations that may take a long time,
// you may hook into Batch API as in the following example.
$ret = array();
// Update 3 users at a time to have an exclamation point after their names.
// (They're really happy that we can do batch API in this hook!)
if (!isset($sandbox['progress'])) {
$sandbox['progress'] = 0;
$sandbox['current_uid'] = 0;
// We'll -1 to disregard the uid 0...
$sandbox['max'] = db_result(db_query('SELECT COUNT(DISTINCT uid) FROM {users}')) - 1;
}
$users = db_query_range("SELECT uid, name FROM {users} WHERE uid > %d ORDER BY uid ASC", $sandbox['current_uid'], 0, 3);
while ($user = db_fetch_object($users)) {
$user->name .= '!';
$ret[] = update_sql("UPDATE {users} SET name = '{$user->name}' WHERE uid = {$user->uid}");
$sandbox['progress']++;
$sandbox['current_uid'] = $user->uid;
}
$ret['#finished'] = empty($sandbox['max']) ? 1 : $sandbox['progress'] / $sandbox['max'];
return $ret;
}
开发者ID:t-web,项目名称:drupal-doxygen-base,代码行数:82,代码来源:install.php
注:本文中的update_sql函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论