本文整理汇总了PHP中table_exists函数的典型用法代码示例。如果您正苦于以下问题:PHP table_exists函数的具体用法?PHP table_exists怎么用?PHP table_exists使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了table_exists函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: xmldb_blocktype_taggedposts_upgrade
function xmldb_blocktype_taggedposts_upgrade($oldversion = 0)
{
if ($oldversion < 2015011500) {
$table = new XMLDBTable('blocktype_taggedposts_tags');
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL, XMLDB_SEQUENCE);
$table->addFieldInfo('block_instance', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL);
$table->addFieldInfo('tag', XMLDB_TYPE_CHAR, 128, null, XMLDB_NOTNULL);
$table->addFieldInfo('tagtype', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL);
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addIndexInfo('tagtagtypeix', XMLDB_INDEX_NOTUNIQUE, array('tag', 'tagtype'));
if (!table_exists($table)) {
create_table($table);
$rs = get_recordset('block_instance', 'blocktype', 'taggedposts', 'id', 'id, configdata');
while ($bi = $rs->FetchRow()) {
// Each block will have only one tag (because we combined this upgrade block
// with the upgrade block for the "multiple tags" enhancement.
$configdata = unserialize($bi['configdata']);
if (!empty($configdata['tagselect'])) {
$todb = new stdClass();
$todb->block_instance = $bi['id'];
$todb->tag = $configdata['tagselect'];
$todb->tagtype = PluginBlocktypeTaggedposts::TAGTYPE_INCLUDE;
insert_record('blocktype_taggedposts_tags', $todb);
}
}
}
}
return true;
}
示例2: create_tables
function create_tables($db_prefix, $drop_tables = 1)
{
//check if tables exists and if drop_tables is 1
table_exists($db_prefix . "session", $drop_tables);
table_exists($db_prefix . "tracks_hh", $drop_tables);
print "<LI> Created tables " . substr($tables, 0, -2) . "<BR />";
}
示例3: cmc_call
function cmc_call($majorcode, $semester, $year)
{
$database = $majorcode . "_" . $semester . "_" . $year . "_req_courses";
if (table_exists($database) != 1) {
if (strpos($semester, 'fall') !== false) {
$Csemester = "Fall";
}
if (strpos($semester, 'spring') !== false) {
$Csemester = "Spring";
}
if (strpos($semester, 'summer') !== false) {
$Csemester = "Summer";
}
$full_semester = $Csemester . " " . $year;
//echo $full_semester;
//echo "$database";
$test = curriculum_request($majorcode, $full_semester);
//echo "<pre>"; print_r($test);
//echo "iambatman live";
if ($test != 1) {
$result = cms_to_database($majorcode, $semester, $year, $test);
// uncheck this after meeting
return 1;
//print_r($test);
} else {
return 0;
}
} else {
return 1;
}
}
示例4: downgrade
public function downgrade(PDO $pdo)
{
if (table_exists($pdo, $pdo->prefix . 'calendar')) {
$pdo->exec(<<<SQL
ALTER TABLE
{$pdo->prefix}calendar
DROP COLUMN
userid
SQL
);
}
if (table_exists($pdo, $pdo->prefix . 'registry')) {
$stmt = $pdo->prepare(<<<SQL
UPDATE
{$pdo->prefix}registry
SET
keyvalue = :version
WHERE
keyname = 'version'
SQL
);
$stmt->bindValue(':version', $this->fromVersion, PDO::PARAM_STR);
$stmt->execute();
}
}
示例5: pre_check_3
function pre_check_3()
{
if (table_exists("bayes_token")) {
return array(false, "Already exists");
} else {
return array(true, "");
}
}
示例6: pre_check_4
function pre_check_4()
{
if (table_exists("maia_tokens")) {
return array(false, "Already exists");
} else {
return array(true, "");
}
}
示例7: clean_stale_tables
/**
* detect and clean up any old test tables lying around
* as of phpunit 3.4, there's no corollary to bootstrap to clean up,
* so this will actually be invoked every single time
* which is quite annoying
*/
public function clean_stale_tables()
{
if (table_exists(new XMLDBTable('config'))) {
if (empty($GLOBALS['TESTDROPSTALEDB']) || $GLOBALS['TESTDROPSTALEDB'] !== true) {
throw new UnitTestBootstrapException('Stale test tables found, and drop option not set. Refusing to run tests');
}
log_info('Stale test tables found, and drop option is set. Dropping them before running tests');
$this->uninstall_mahara();
log_info('Done');
}
}
示例8: migrate
function migrate()
{
global $db_tables;
foreach ($db_tables as $table => $fields) {
if (table_exists($table)) {
//compare the field names of the table with the field names in the array
//describe table
$existing_fields = array();
$field_names = array();
$result = mysql_query("DESCRIBE " . $table);
while ($data = mysql_fetch_assoc($result)) {
array_push($existing_fields, $data["Field"]);
}
foreach ($fields as $name => $type) {
array_push($field_names, $name);
}
//get any fields that were not present. Subtract existing fields
$field_names = array_diff($field_names, $existing_fields);
if (sizeof($field_names) > 0) {
//if there is any difference between existing and expected tables
foreach ($field_names as $name) {
$sql = "ALTER TABLE `{$table}` ADD COLUMN `{$name}` " . $db_tables[$table][$name] . ";";
if (mysql_query($sql)) {
echo "<BR> Added column {$name} to {$table} <BR>";
} else {
echo "<BR> Failed to add {$name} to {$table} <BR>";
}
}
} else {
echo "<BR>No missing fields in {$table}";
}
} else {
//creates a new table with our default timestamps
$sql = "CREATE TABLE `{$table}` (\n `id` int(11) NOT NULL auto_increment,\n `created_at` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,\n `updated_at` timestamp NOT NULL default '0000-00-00 00:00:00',";
foreach ($fields as $name => $type) {
$sql .= "`{$name}` {$type},\n";
}
$sql .= "PRIMARY KEY (`id`)\n ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1";
if (mysql_query($sql)) {
echo "<BR> Added table {$table} <BR>";
} else {
echo "<BR> Failed to add table {$table} <BR>";
}
}
}
}
示例9: install
public function install()
{
if (!table_exists('__meta_user') && !table_exists('__meta_code')) {
$sql = "CREATE TABLE IF NOT EXISTS `__meta_code` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `table` varchar(32) NOT NULL,\n `action` varchar(32) NOT NULL,\n `code` mediumtext NOT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `table` (`table`,`action`)\n)";
run_sql($sql);
$sql = "CREATE TABLE IF NOT EXISTS `__meta_user` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `email` varchar(255) NOT NULL,\n `password` varchar(32) NOT NULL,\n PRIMARY KEY (`id`)\n) ";
run_sql($sql);
$email = 'admin' . rand(1, 999) . '@admin.com';
$password = substr(md5(rand(10000, 8000) . time()), 0, 8);
$sql = "INSERT INTO `__meta_user` ( `email` , `password` ) VALUES ( '" . s($email) . "' , '" . md5($password) . "' ) ";
run_sql($sql);
if (mysql_errno() == 0) {
return info_page("初始化成功,请使用【" . $email . "】和【" . $password . "】<a href='?a=login' target='_blank'>登录</a>。您可以通过phpmyadmin修改【__meta_user】表来管理账户" . '<br /><br /><a href="http://ftqq.com/2012/01/10/build-a-rest-server-in-5-minutes/" target="_blank">使用教程</a>');
}
}
return info_page("已经初始化或数据库错误,请稍后重试");
}
示例10: log_event
/**
* Logs an event to make sure it's not triggered again
* @params:
* $event :array
* $event['issue_id'] :integer, the id of the issue to be logeed with the event
* $event['initiative_id'] :integer, the id of the initiative to be looged with the event
* $event['job'] :string, the job that handled the issue
* @returns true on success, dies otherwise
*/
function log_event($event)
{
global $db_events_table;
//the events table's name for each bot is defined in update_twitter_bot.php right before the bot is processed
$time = time();
if (!table_exists($db_events_table)) {
create_table($db_events_table, 'time INT, issue_id INT, initiative_id INT, job CHAR(80)');
}
$query = "INSERT INTO {$db_events_table} (time, issue_id, initiative_id, job) VALUES({$time}, {$event['issue_id']} , {$event['initiative_id']} , '{$event['job']}')";
$result = mysql_query($query);
$error = mysql_errno();
if ($error != 0) {
log_this("error: tried to log event ({$event['issue_id']} , {$event['issue_id']}, '{$event['job']})", mysql_error() . ": \n" . $query);
die("Unable to log event. MySQL error: " . $error);
} else {
log_this("success: logged event ({$event['issue_id']} ,{$event['initiative_id']}, '{$event['job']})");
return true;
}
}
示例11: xmldb_block_tao_certification_path_upgrade
function xmldb_block_tao_certification_path_upgrade($oldversion = 0)
{
global $CFG, $THEME, $db;
$result = true;
/// And upgrade begins here. For each one, you'll need one
/// block of code similar to the next one. Please, delete
/// this comment lines once this file start handling proper
/// upgrade code.
/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
/// $result = result of "/lib/ddllib.php" function calls
/// }
if ($result && $oldversion < 2008111204) {
//New version in version.php
$table = new XMLDBTable('tao_user_certification_status');
if (!table_exists($table)) {
//this table doesn't exist so create it!
$result = install_from_xmldb_file("{$CFG->dirroot}/blocks/tao_certification_path/db/install.xml");
}
}
return $result;
}
示例12: log_this
/**
* Appends a row to the log table
* @params
* $key :string, a short description of the data to be stored
* $data :the data to be stored
* @returns true on success, dies otherwise
*/
function log_this($key, $data = '')
{
$key = mysql_escape_string($key);
$data = mysql_escape_string($data);
if (!table_exists(DB_TABLE_LOG)) {
create_table(DB_TABLE_LOG, "id INT AUTO_INCREMENT, time INT, label TEXT, data TEXT, PRIMARY KEY (id)");
} else {
// nothing is kept older than 3 days
$time = time() - 60 * 60 * 24 * 3;
$query = "DELETE from " . DB_TABLE_LOG . " WHERE time<{$time}";
$result = mysql_query($query);
if (mysql_errno != 0) {
die("MySQL error: " . mysql_errno());
}
}
$query = "INSERT INTO " . DB_TABLE_LOG . "(time, label, data) VALUES ( " . time() . ", \"{$key}\", \"{$data}\")";
$result = mysql_query($query);
if (mysql_errno != 0) {
die("MySQL error: " . mysql_errno());
} else {
return true;
}
}
示例13: cm_load_config
/**
* Load up the curriculum management global config values (copied from Moodle).
*
*/
function cm_load_config()
{
global $CFG, $CURMAN;
/// Ensure that the table actually exists before we query records from it.
require_once $CFG->libdir . '/ddllib.php';
$table = new XMLDBTable(CMCONFIGTABLE);
if (!table_exists($table)) {
return $CURMAN->config;
}
if ($configs = get_records(CMCONFIGTABLE)) {
/// Allow settings in the config.php file to override.
$localcfg = (array) $CURMAN->config;
foreach ($configs as $config) {
if (!isset($localcfg[$config->name])) {
$localcfg[$config->name] = $config->value;
}
}
$localcfg = (object) $localcfg;
return $localcfg;
} else {
// preserve $CFG if DB returns nothing or error
return $CURMAN->config;
}
}
示例14: get_site_languages
function get_site_languages($lang = '', $active = '')
{
if (table_exists('site_languages', MAINSITE_DB)) {
$db_languages = MAINSITE_DB;
} else {
$db_languages = CAMALEO_DB;
}
# set the database to use
#
$sql = 'SELECT ' . '`site_languages`.`lang`, ' . '`site_languages`.`descrizione`, ' . 'LCASE(`site_languages`.`flag`) AS flag, ' . 'LCASE(`site_languages`.`iso`) AS iso, ' . '`site_languages`.`switch` ' . 'FROM `' . $db_languages . '`.`site_languages` ' . 'WHERE 1=1 ';
if ($lang != '') {
$sql .= 'AND lang = \'' . mysql_real_escape_string($lang) . '\' ';
}
if ($active != '') {
$sql .= 'AND switch = 1 ';
}
$sql .= 'ORDER BY switch DESC, descrizione ASC ';
#
$sth = db_query($sql, __LINE__, __FILE__);
$rows = db_fetch($sth[0], false);
//echo $sql.'<br>';
//var_dump($rows);
return $rows;
}
示例15: invoke
/**
* Invoke method, every class will have its own
* returns true/false on completion, setting both
* errormsg and output as necessary
*/
function invoke()
{
parent::invoke();
$result = true;
/// Set own core attributes
$this->does_generate = ACTION_GENERATE_HTML;
/// These are always here
global $CFG, $XMLDB, $db;
/// And we nedd some ddl suff
require_once $CFG->libdir . '/ddllib.php';
/// Here we'll acummulate all the wrong fields found
$wrong_fields = array();
/// Correct fields must be type bigint for MySQL and int8 for PostgreSQL
switch ($CFG->dbfamily) {
case 'mysql':
$correct_type = 'bigint';
break;
case 'postgres':
$correct_type = 'int8';
break;
default:
$correct_type = NULL;
}
/// Do the job, setting $result as needed
/// Get the confirmed to decide what to do
$confirmed = optional_param('confirmed', false, PARAM_BOOL);
/// If not confirmed, show confirmation box
if (!$confirmed) {
$o = '<table class="generalbox" border="0" cellpadding="5" cellspacing="0" id="notice">';
$o .= ' <tr><td class="generalboxcontent">';
$o .= ' <p class="centerpara">' . $this->str['confirmcheckbigints'] . '</p>';
if ($CFG->dbfamily == 'mysql') {
$o .= ' <p class="centerpara">' . $this->str['mysqlextracheckbigints'] . '</p>';
}
$o .= ' <table class="boxaligncenter" cellpadding="20"><tr><td>';
$o .= ' <div class="singlebutton">';
$o .= ' <form action="index.php?action=check_bigints&sesskey=' . sesskey() . '&confirmed=yes" method="post"><fieldset class="invisiblefieldset">';
$o .= ' <input type="submit" value="' . $this->str['yes'] . '" /></fieldset></form></div>';
$o .= ' </td><td>';
$o .= ' <div class="singlebutton">';
$o .= ' <form action="index.php?action=main_view" method="post"><fieldset class="invisiblefieldset">';
$o .= ' <input type="submit" value="' . $this->str['no'] . '" /></fieldset></form></div>';
$o .= ' </td></tr>';
$o .= ' </table>';
$o .= ' </td></tr>';
$o .= '</table>';
$this->output = $o;
} else {
/// The back to edit table button
$b = ' <p class="centerpara buttons">';
$b .= '<a href="index.php">[' . $this->str['back'] . ']</a>';
$b .= '</p>';
/// Iterate over $XMLDB->dbdirs, loading their XML data to memory
if ($XMLDB->dbdirs) {
$dbdirs =& $XMLDB->dbdirs;
$o = '<ul>';
foreach ($dbdirs as $dbdir) {
/// Only if the directory exists
if (!$dbdir->path_exists) {
continue;
}
/// Load the XML file
$xmldb_file = new XMLDBFile($dbdir->path . '/install.xml');
/// Load the needed XMLDB generator
$classname = 'XMLDB' . $CFG->dbtype;
$generator = new $classname();
$generator->setPrefix($CFG->prefix);
/// Only if the file exists
if (!$xmldb_file->fileExists()) {
continue;
}
/// Load the XML contents to structure
$loaded = $xmldb_file->loadXMLStructure();
if (!$loaded || !$xmldb_file->isLoaded()) {
notify('Errors found in XMLDB file: ' . $dbdir->path . '/install.xml');
continue;
}
/// Arriving here, everything is ok, get the XMLDB structure
$structure = $xmldb_file->getStructure();
$o .= ' <li>' . str_replace($CFG->dirroot . '/', '', $dbdir->path . '/install.xml');
/// Getting tables
if ($xmldb_tables = $structure->getTables()) {
$o .= ' <ul>';
/// Foreach table, process its fields
foreach ($xmldb_tables as $xmldb_table) {
/// Skip table if not exists
if (!table_exists($xmldb_table)) {
continue;
}
/// Fetch metadata from phisical DB. All the columns info.
if ($metacolumns = $db->MetaColumns($CFG->prefix . $xmldb_table->getName())) {
$metacolumns = array_change_key_case($metacolumns, CASE_LOWER);
} else {
//// Skip table if no metacolumns is available for it
continue;
//.........这里部分代码省略.........