本文整理汇总了PHP中run_sql_script函数的典型用法代码示例。如果您正苦于以下问题:PHP run_sql_script函数的具体用法?PHP run_sql_script怎么用?PHP run_sql_script使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了run_sql_script函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: subsite_manager_runonce
function subsite_manager_runonce()
{
// register a new substype in the database and link it to the right classname
add_subtype("site", Subsite::SUBTYPE, "Subsite");
// Update the database with extra columns for multisite
run_sql_script(dirname(dirname(__FILE__)) . "/scripts/add_columns.sql");
}
示例2: gcm_register
/**
* Created by PhpStorm.
* Date: 12/7/2015
* Time: 12:30 PM
* @param $regId
* @param $account
* @param $name
* @return mixed
* @throws InvalidParameterException
*/
function gcm_register($regId, $account, $name)
{
if (!$account) {
$response['status'] = 1;
$response['result'] = 'please enter valid user account';
return $response;
exit;
} else {
$user = get_user_by_username($account);
if (!$user) {
throw new InvalidParameterException('registration:usernamenotvalid');
$response['status'] = 1;
$response['result'] = 'user account not valid';
return $response;
exit;
}
}
// create the tables for API stats
$path = elgg_get_plugins_path();
run_sql_script($path . "elgg_with_rest_api/schema/mysql.sql");
if ($account && $regId) {
$elgg_post = 1;
$elgg_message = 1;
// Store user details in db
include_once $path . 'elgg_with_rest_api/lib/DB_Register_Functions.php';
include_once $path . 'elgg_with_rest_api/lib/GCM.php';
$db = new DB_Register_Functions();
$gcm = new GCM();
if ($db->checkUser($regId)) {
$res = $db->updateUser($name, $account, $regId, $elgg_post, $elgg_message);
$response['status'] = 0;
$response['result'] = "success update gcm regId and user info";
} else {
$res = $db->storeUser($name, $account, $regId, $elgg_post, $elgg_message);
$registration_ids = array($regId);
$message = array("from_name" => "Core Server", "subject" => "Core App Notification", "message" => "Enable Receive Notification");
$result = $gcm->send_notification($registration_ids, $message);
$response['status'] = 0;
$response['result'] = "success Insert gcm regId and user info";
}
} else {
// user details missing
$response['status'] = 1;
$response['result'] = 'Missing name or reg id';
}
return $response;
}
示例3: db_upgrade
/**
* ***************************************************************************
* NOTE: If this is ever removed from Elgg, sites lose the ability to upgrade
* from 1.7.x and earlier to the latest version of Elgg without upgrading to
* 1.8 first.
* ***************************************************************************
*
* Upgrade the database schema in an ordered sequence.
*
* Executes all upgrade files in elgg/engine/schema/upgrades/ in sequential order.
* Upgrade files must be in the standard Elgg release format of YYYYMMDDII.sql
* where II is an incrementor starting from 01.
*
* Files that are < $version will be ignored.
*
* @warning Plugin authors should not call this function directly.
*
* @param int $version The version you are upgrading from in the format YYYYMMDDII.
* @param string $fromdir Optional directory to load upgrades from. default: engine/schema/upgrades/
* @param bool $quiet If true, suppress all error messages. Only use for the upgrade from <=1.6.
*
* @return int The number of upgrades run.
* @see upgrade.php
* @see version.php
* @deprecated 1.8 Use PHP upgrades for sql changes.
*/
function db_upgrade($version, $fromdir = "", $quiet = FALSE)
{
global $CONFIG;
elgg_deprecated_notice('db_upgrade() is deprecated by using PHP upgrades.', 1.8);
$version = (int) $version;
if (!$fromdir) {
$fromdir = $CONFIG->path . 'engine/schema/upgrades/';
}
$i = 0;
if ($handle = opendir($fromdir)) {
$sqlupgrades = array();
while ($sqlfile = readdir($handle)) {
if (!is_dir($fromdir . $sqlfile)) {
if (preg_match('/^([0-9]{10})\\.(sql)$/', $sqlfile, $matches)) {
$sql_version = (int) $matches[1];
if ($sql_version > $version) {
$sqlupgrades[] = $sqlfile;
}
}
}
}
asort($sqlupgrades);
if (sizeof($sqlupgrades) > 0) {
foreach ($sqlupgrades as $sqlfile) {
// hide all errors.
if ($quiet) {
try {
run_sql_script($fromdir . $sqlfile);
} catch (DatabaseException $e) {
error_log($e->getmessage());
}
} else {
run_sql_script($fromdir . $sqlfile);
}
$i++;
}
}
}
return $i;
}
示例4: installDatabase
/**
* Create the database tables
*
* @return bool
*/
protected function installDatabase()
{
global $CONFIG;
try {
run_sql_script("{$CONFIG->path}engine/schema/mysql.sql");
} catch (Exception $e) {
$msg = $e->getMessage();
if (strpos($msg, 'already exists')) {
$msg = elgg_echo('install:error:tables_exist');
}
register_error($msg);
return FALSE;
}
return TRUE;
}
示例5: apply_fixes
function apply_fixes($version)
{
$queries = array();
if ($version == 'sfee3.3') {
$res = db_query("SELECT COUNT(*) AS applied FROM database_changes WHERE filename='sfee3.3fixes'");
if ($res && db_result($res, 0, 'applied') == '0') {
show("Converting SFEE3.3 to SFEE3.0\n");
run_script(array('filename' => 'sfee3.3-3.0-1.sql', 'ext' => 'sql'));
run_script(array('filename' => 'sfee3.3-3.0-2.php', 'ext' => 'php'));
run_script(array('filename' => 'sfee3.3-3.0-3.sql', 'ext' => 'sql'));
show("Converting SFEE3.0 to SF2.6\n");
//sfee3.0-sf26-1.sql
run_script(array('filename' => 'sfee3.0-sf26-1.sql', 'ext' => 'sql'));
run_script(array('filename' => 'sfee3.0-sf26-2.php', 'ext' => 'php'));
$queries[] = "INSERT INTO database_changes (filename) VALUES ('sfee3.3fixes')";
}
} else {
if ($version == 'sfee3.0') {
$res = db_query("SELECT COUNT(*) AS applied FROM database_changes WHERE filename='sfee3.0fixes'");
if ($res && db_result($res, 0, 'applied') == '0') {
run_script(array('filename' => 'sfee3.0-sf26-1.sql', 'ext' => 'sql'));
run_script(array('filename' => 'sfee3.0-sf26-2.php', 'ext' => 'php'));
$queries[] = "INSERT INTO database_changes (filename) VALUES ('sfee3.0fixes')";
}
} else {
if ($version == '2.5') {
$res = db_query("SELECT COUNT(*) AS applied FROM database_changes WHERE filename='2.5fixes'");
if ($res && db_result($res, 0, 'applied') == '0') {
show("Applying fixes for version 2.5\n");
$queries[] = "ALTER TABLE project_task ADD CONSTRAINT project_task_group_project_id_f CHECK (1 = 1)";
$queries[] = "INSERT INTO database_changes (filename) VALUES ('2.5fixes')";
}
} else {
if ($version == '2.6') {
$res = db_query("SELECT COUNT(*) AS applied FROM database_changes WHERE filename='2.6fixes'");
if ($res && db_result($res, 0, 'applied') == '0') {
show("Applying fixes for version 2.6\n");
$queries[] = "ALTER TABLE project_task ADD CONSTRAINT project_task_group_project_id_f CHECK (1 = 1)";
$queries[] = "INSERT INTO database_changes (filename) VALUES ('2.6fixes')";
}
} else {
if ($version == '3.0pre5') {
$res = db_query("SELECT COUNT(*) AS applied FROM database_changes WHERE filename='3.0pre5fixes'");
if ($res && db_result($res, 0, 'applied') == '0') {
show("Applying fixes for version 3.0pre5\n");
if (!run_sql_script('fix-gforge3.0pre5.sql')) {
show("Error applying fixes for version 3.0pre5\n");
//exit();
}
$queries[] = "INSERT INTO database_changes (filename) VALUES ('3.0pre5fixes')";
}
} else {
if ($version == '3.0pre6') {
$res = db_query("SELECT COUNT(*) AS applied FROM database_changes WHERE filename='3.0pre6fixes'");
if ($res && db_result($res, 0, 'applied') == '0') {
show("Applying fixes for version 3.0pre6\n");
$queries[] = "ALTER TABLE project_task ADD CONSTRAINT project_task_group_project_id_f CHECK (1 = 1)";
$queries[] = "INSERT INTO database_changes (filename) VALUES ('3.0pre6fixes')";
}
} else {
if ($version == '3.0pre7') {
$res = db_query("SELECT COUNT(*) AS applied FROM database_changes WHERE filename='3.0pre7fixes'");
if ($res && db_result($res, 0, 'applied') == '0') {
show("Applying fixes for version 3.0pre7\n");
$queries[] = "ALTER TABLE project_task ADD CONSTRAINT project_task_group_project_id_f CHECK (1 = 1)";
$queries[] = "INSERT INTO database_changes (filename) VALUES ('3.0pre7fixes')";
}
}
}
}
}
}
}
}
//db_begin();
foreach ($queries as $query) {
$res = db_query($query);
if (!$res) {
show("ERROR: " . db_error() . "\n");
// db_rollback();
return false;
}
}
//db_commit();
return true;
}
示例6: db_upgrade
/**
* Upgrade the database schema in an ordered sequence.
*
* Makes use of schema upgrade files
*
* This is a about as core as it comes, so don't start running this from your plugins!
*
* @param int $version The version you are upgrading from (usually given in the Elgg version format of YYYYMMDDXX - see version.php for example)
* @param string $fromdir Optional directory to load upgrades from (default: engine/schema/upgrades/)
* @return bool
*/
function db_upgrade($version, $fromdir = "")
{
global $CONFIG;
// Elgg and its database must be installed to upgrade it!
if (!is_db_installed() || !is_installed()) {
return false;
}
$version = (int) $version;
if (!$fromdir) {
$fromdir = $CONFIG->path . 'engine/schema/upgrades/';
}
if ($handle = opendir($fromdir)) {
$sqlupgrades = array();
while ($sqlfile = readdir($handle)) {
if (!is_dir($fromdir . $sqlfile)) {
if (preg_match('/([0-9]*)\\.sql/', $sqlfile, $matches)) {
$sql_version = (int) $matches[1];
if ($sql_version > $version) {
$sqlupgrades[] = $sqlfile;
}
}
}
}
asort($sqlupgrades);
if (sizeof($sqlupgrades) > 0) {
foreach ($sqlupgrades as $sqlfile) {
try {
run_sql_script($fromdir . $sqlfile);
} catch (DatabaseException $e) {
error_log($e->getmessage());
}
}
}
}
return true;
}
示例7: dobackup
function dobackup()
{
global $lang_backup, $backup_dir, $tables_backup_realmd, $tables_backup_characters, $output, $realm_db, $characters_db, $realm_id, $tab_backup_user_realmd, $tab_backup_user_characters;
if (empty($_GET['backup_action']) || empty($_GET['backup_from_to'])) {
redirect("backup.php?error=1");
} else {
$backup_action = addslashes($_GET['backup_action']);
$backup_from_to = addslashes($_GET['backup_from_to']);
}
if ("load" == $backup_action && "file" == $backup_from_to) {
if (!eregi("(\\.(sql|qbquery))\$", $_FILES["uploaded_file"]["name"])) {
error($lang_backup['upload_sql_file_only']);
}
$uploaded_filename = str_replace(" ", "_", $_FILES["uploaded_file"]["name"]);
$uploaded_filename = preg_replace("/[^_A-Za-z0-9-\\.]/i", '', $uploaded_filename);
$file_name_new = $uploaded_filename . "_" . date("m.d.y_H.i.s") . ".sql";
move_uploaded_file($_FILES["uploaded_file"]["tmp_name"], "{$backup_dir}/{$file_name_new}") or die(error("{$lang_backup['upload_err_write_permission']} {$backup_dir}"));
if (file_exists("{$backup_dir}/{$file_name_new}")) {
require_once "libs/db_lib/sql_lib.php";
$use_db = addslashes($_POST['use_db']);
if ($use_db == $realm_db['name']) {
$queries = run_sql_script($realm_db['addr'], $realm_db['user'], $realm_db['pass'], $realm_db['name'], "{$backup_dir}/{$file_name_new}", true);
} else {
foreach ($characters_db as $db) {
if ($use_db == $db['name']) {
$queries = run_sql_script($db['addr'], $db['user'], $db['pass'], $db['name'], "{$backup_dir}/{$file_name_new}", true);
}
}
}
redirect("backup.php?error=4&tot={$queries}");
} else {
error($lang_backup['file_not_found']);
}
} elseif ("load" == $backup_action && "web" == $backup_from_to) {
if (empty($_POST['selected_file_name'])) {
redirect("backup.php?error=1");
} else {
$file_name = addslashes($_POST['selected_file_name']);
}
if (file_exists("{$backup_dir}/{$file_name}")) {
require_once "libs/db_lib/sql_lib.php";
$use_db = addslashes($_POST['use_db']);
if ($use_db == $realm_db['name']) {
$queries = run_sql_script($realm_db['addr'], $realm_db['user'], $realm_db['pass'], $realm_db['name'], "{$backup_dir}/{$file_name}", false);
} else {
foreach ($characters_db as $db) {
if ($use_db == $db['name']) {
$queries = run_sql_script($db['addr'], $db['user'], $db['pass'], $db['name'], "{$backup_dir}/{$file_name}", false);
}
}
}
redirect("backup.php?error=4&tot={$queries}");
} else {
error($lang_backup['file_not_found']);
}
} elseif ("save" == $backup_action && "file" == $backup_from_to) {
//save and send to user
$struc_backup = addslashes($_GET['struc_backup']);
$save_all_realms = addslashes($_GET['save_all_realms']);
if ($save_all_realms) {
$temp_id = "all_realms";
} else {
$temp_id = "realmid_" . $realm_id;
}
$file_name_new = $temp_id . "_backup_" . date("m.d.y_H.i.s") . ".sql";
$fp = fopen("{$backup_dir}/{$file_name_new}", 'w') or die(error($lang_backup['file_write_err']));
fwrite($fp, "CREATE DATABASE /*!32312 IF NOT EXISTS*/ {$realm_db['name']};\n") or die(error($lang_backup['file_write_err']));
fwrite($fp, "USE {$realm_db['name']};\n\n") or die(error($lang_backup['file_write_err']));
fclose($fp);
require_once "libs/db_lib/sql_lib.php";
foreach ($tables_backup_realmd as $value) {
sql_table_dump($realm_db['addr'], $realm_db['user'], $realm_db['pass'], $realm_db['name'], $value, $struc_backup, "{$backup_dir}/{$file_name_new}");
}
if ($save_all_realms) {
foreach ($characters_db as $db) {
$fp = fopen("{$backup_dir}/{$file_name_new}", 'r+') or die(error($lang_backup['file_write_err']));
fseek($fp, 0, SEEK_END);
fwrite($fp, "CREATE DATABASE /*!32312 IF NOT EXISTS*/ {$db['name']};\n") or die(error($lang_backup['file_write_err']));
fwrite($fp, "USE {$db['name']};\n\n") or die(error($lang_backup['file_write_err']));
fclose($fp);
foreach ($tables_backup_characters as $value) {
sql_table_dump($db['addr'], $db['user'], $db['pass'], $db['name'], $value, $struc_backup, "{$backup_dir}/{$file_name_new}");
}
}
} else {
$fp = fopen("{$backup_dir}/{$file_name_new}", 'r+') or die(error($lang_backup['file_write_err']));
fseek($fp, 0, SEEK_END);
fwrite($fp, "CREATE DATABASE /*!32312 IF NOT EXISTS*/ {$characters_db[$realm_id]['name']};\n") or die(error($lang_backup['file_write_err']));
fwrite($fp, "USE {$characters_db[$realm_id]['name']};\n\n") or die(error($lang_backup['file_write_err']));
fclose($fp);
foreach ($tables_backup_characters as $value) {
sql_table_dump($characters_db[$realm_id]['addr'], $characters_db[$realm_id]['user'], $characters_db[$realm_id]['pass'], $characters_db[$realm_id]['name'], $value, $struc_backup, "{$backup_dir}/{$file_name_new}");
}
}
Header("Content-type: application/octet-stream");
Header("Content-Disposition: attachment; filename={$file_name_new}");
$fp = fopen("{$backup_dir}/{$file_name_new}", 'r') or die(error($lang_backup['file_write_err']));
while (!feof($fp)) {
$output_file = fread($fp, 1024);
echo $output_file;
//.........这里部分代码省略.........
示例8: dirname
* @subpackage Core
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
* @author Curverider Ltd
* @copyright Curverider Ltd 2008-2009
* @link http://elgg.org/
*/
/**
* Start the Elgg engine
*/
require_once dirname(__FILE__) . "/engine/start.php";
global $CONFIG;
elgg_set_viewtype('failsafe');
/**
* If we're installed, go back to the homepage
*/
if (is_installed() && is_db_installed() && datalist_get('installed')) {
forward("index.php");
}
/**
* Install the database
*/
if (!is_db_installed()) {
validate_platform();
run_sql_script(dirname(__FILE__) . "/engine/schema/mysql.sql");
init_site_secret();
system_message(elgg_echo("installation:success"));
}
/**
* Load the front page
*/
page_draw(elgg_echo("installation:settings"), elgg_view_layout("one_column", elgg_view("settings/install")));
示例9: run_sql_script
<?php
try {
run_sql_script(__DIR__ . '/sql/activate.sql');
run_sql_script(__DIR__ . '/sql/profile_strength.sql');
//mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
//$DBprefix=elgg_get_config('dbprefix');
//$DBname=elgg_get_config('dbname');
//$mysqli = new mysqli(elgg_get_config('dbhost'), elgg_get_config('dbuser'), elgg_get_config('dbpass'), elgg_get_config('dbname'));
//if ($mysqli->connect_errno) {
// throw new Exception($mysqli->connect_errno);
//}
//if (!$mysqli->query("DROP PROCEDURE IF EXISTS GET_suggestedFriends") ||
//!$mysqli->query("CREATE PROCEDURE `GET_suggestedFriends`(IN `UserGUID` BIGINT(20),IN Sug_Limit INT) BEGIN select fof.guid_two,ue.username FROM {$DBprefix}entities as e INNER JOIN {$DBprefix}users_entity ue ON ue.guid = e.guid INNER JOIN {$DBprefix}entity_relationships fr ON fr.guid_one = UserGUID AND fr.relationship = 'friend' INNER JOIN {$DBprefix}entity_relationships fof ON fof.guid_one = fr.guid_two AND fof.relationship = 'friend' WHERE ue.banned='no' and e.guid NOT IN (SELECT f.guid_two FROM {$DBprefix}entity_relationships f WHERE f.guid_one = UserGUID AND f.relationship = 'friend') and fof.guid_two = e.guid and e.guid != UserGUID GROUP BY e.guid ORDER BY fof.guid_two desc, ue.last_action DESC LIMIT Sug_Limit;END;")) {
// throw new Exception($mysqli->errno);
//}
//$mysqli->close();
// run_sql_script(__DIR__ . '/sql/activate.sql');
} catch (Exception $e) {
$errMess = $e->getMessage();
$errStack = $e->getTraceAsString();
$errType = $e->getCode();
gc_err_logging($errMess, $errStack, 'WET4 Theme Activation', $errType);
//echo 'Caught exception: ', $e->getMessage(), "\n";
//$mysqli->close();
}
示例10: scraper_upgrade_20161410b
function scraper_upgrade_20161410b()
{
// Setup MySQL databases
run_sql_script(dirname(dirname(__FILE__)) . '/install/mysql.sql');
}
示例11: elgg_get_config
<?php
// Create a new table that will hold geometry data for entities
$prefix = elgg_get_config('dbprefix');
$tables = get_db_tables();
if (!in_array("{$prefix}entity_geometry", $tables)) {
set_time_limit(0);
run_sql_script(__DIR__ . '/sql/create_table.sql');
elgg_add_admin_notice("geo:create_table", "MySQL table for storing entity geometry with the name '{$prefix}entity_geometry' has been created");
// Populate geometry table with know information about entities
$batch = new ElggBatch('elgg_get_entities_from_metadata', array('metadata_name_value_pairs' => array(array('name' => 'geo:lat', 'value' => null, 'operand' => 'NOT NULL'), array('name' => 'geo:lat', 'value' => '0', 'operand' => '!='), array('name' => 'geo:long', 'value' => null, 'operand' => 'NOT NULL'), array('name' => 'geo:long', 'value' => '0', 'operand' => '!=')), 'order_by' => 'e.guid ASC', 'limit' => 0));
$i = $k = 0;
foreach ($batch as $b) {
if (elgg_instanceof($b)) {
$lat = $b->getLatitude();
$long = $b->getLongitude();
if ($lat && $long) {
$query = "INSERT INTO {$prefix}entity_geometry (entity_guid, geometry)\r\n\t\t\t\t\t\t\tVALUES ({$b->guid}, GeomFromText('POINT({$lat} {$long})'))\r\n\t\t\t\t\t\t\tON DUPLICATE KEY UPDATE geometry=GeomFromText('POINT({$lat} {$long})')";
if (insert_data($query)) {
$i++;
}
} else {
$k++;
}
}
}
elgg_add_admin_notice("geo:import", "'{$prefix}entity_geometry' has been populated with information about the location of {$i} entities; geographic coordinates for {$k} entities were incorrect");
}
示例12: run_sql_script
<?php
// Setup MySQL databases
run_sql_script(__DIR__ . '/install/mysql.sql');
示例13: get_data
<?php
$result = get_data("show tables where 'elgg_entity_views'");
if (count($result) === 0) {
run_sql_script(dirname(__FILE__) . '/sql/views_table.sql');
}
示例14: get_data
<?php
$result = get_data("show tables like 'oauth_%'");
if (count($result) === 0) {
run_sql_script(__DIR__ . '/sql/oauth_tables.sql');
}
$result = get_data("show tables like 'elgg_push_notifications_%'");
if (count($result) === 0) {
run_sql_script(__DIR__ . '/sql/push_tables.sql');
}
示例15: Data
/**
* Data Add
*
* @access system
* @return return;
*/
public static function Data($query, $type)
{
global $CONFIG;
$query = str_replace('prefixes_', $CONFIG->dbprefix, $query);
if (!empty($query) && $type == 'get') {
return get_data($query);
}
if (!empty($query) && $type == 'delete') {
return delete_data($query);
}
if (!empty($query) && $type == 'add') {
return insert_data($query);
}
if (!empty($query) && $type == 'run') {
return run_sql_script($query);
}
}