本文整理汇总了PHP中loadDatabase函数的典型用法代码示例。如果您正苦于以下问题:PHP loadDatabase函数的具体用法?PHP loadDatabase怎么用?PHP loadDatabase使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了loadDatabase函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register_user
function register_user()
{
// get passwordHash library for backwards compatability.
require 'password.php';
// get database connection object
require 'dbConnector.php';
$db = loadDatabase();
// Get check_user function
require 'check_user_db.php';
// get user submitted form
$username = stripslashes($_POST['username']);
$password = stripslashes($_POST['password']);
$email = stripslashes($_POST['email']);
// Check if username exists using check_user()
if (check_user($db, $username)) {
$message = "Username '{$username}' already exists.";
} else {
// hash and salt password
$passwordHash = password_hash($password, PASSWORD_DEFAULT);
// Prepared statement to insert a user
$stmt = $db->prepare("INSERT INTO user (username, email, password)\n VALUES (:username, :email, :passwordHash);");
$stmt->bindValue(':username', $username);
$stmt->bindValue(':passwordHash', $passwordHash);
$stmt->bindValue(':email', $email);
$stmt->execute();
$_SESSION['logged_user'] = $username;
$message = "{$username}, you are now registered.";
}
return $message;
}
示例2: add_product
function add_product($code, $name, $price, $description, $img)
{
$db = loadDatabase();
$img = '/media/products/' . $img;
$query = 'INSERT INTO products
(productCode, productName, listPrice, description, img)
VALUES
(:code, :name, :price, :description, :img)';
$statement = $db->prepare($query);
$statement->bindValue(':code', $code);
$statement->bindValue(':name', $name);
$statement->bindValue(':price', $price);
$statement->bindValue(':description', $description);
$statement->bindValue(':img', $img);
$statement->execute();
$statement->closeCursor();
}
示例3: edit_user
function edit_user($current_username, $new_username, $new_email)
{
$db = loadDatabase();
$query = 'UPDATE user SET username = :new_username, email = :new_email
WHERE username = :username';
$statement = $db->prepare($query);
$statement->bindValue(':username', $current_username);
$statement->bindValue(':new_username', $new_username);
$statement->bindValue(':new_email', $new_email);
$statement->execute();
if ($statement->rowCount() > 0) {
$_SESSION['logged_user'] = $new_username;
$message = 'User was succesfully updated.';
} else {
$message = 'User could not be updated.';
}
return $message;
}
示例4: login_user
function login_user()
{
$db = loadDatabase();
$username = stripslashes($_POST['username']);
$password = stripslashes($_POST['password']);
$stmt = $db->prepare('SELECT * FROM user WHERE username = :username');
$stmt->bindValue(':username', $username);
$stmt->execute();
$user = $stmt->fetch();
// Check if user is in database
if ($user['username'] and password_verify($password, $user['password'])) {
// echo $user['username'], $user['password'];
// User is in DB, log them in.
$_SESSION['logged_user'] = $user['username'];
$message = $user['username'] . ' You are now logged in!';
// Check admin status and set session to reflect.
if ($user['admin'] == true) {
$_SESSION['admin_user'] = true;
}
} else {
$message = "The Username or Password entered was not found in our database.";
}
return $message;
}
示例5: session_start
<?php
session_start();
// Calling with a POST?
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$result = "";
// Is everything set correctly?
if (isset($_POST["oPassword"]) && isset($_POST["nPassword"]) && isset($_POST["rnPassword"]) && isset($_POST["username"])) {
// Right person logged in?
if ($_POST["username"] === $_SESSION["user"]) {
require '../database/password.php';
require '../database/databaseConnect.php';
$db = loadDatabase();
$result = "DB LOADED";
$user = $db->query("SELECT * FROM users WHERE user_name = '" . $_SESSION["user"] . "' LIMIT 1");
if ($user === false || $user->rowCount() === 0) {
$result = "User doesn't not exist.";
} else {
$user->setFetchMode(PDO::FETCH_ASSOC);
$user = $user->fetch();
$result = "USER FETCHED";
// Password correct?
if (password_verify($_POST["oPassword"], $user["user_pass"])) {
// Password not the same?
if ($_POST["nPassword"] !== $_POST["rnPassword"]) {
$result = "Passwords don't match!";
} else {
if ($_POST["nPassword"] === $_POST["oPassword"]) {
$result = "Old and new passwords cannot be the same.";
} else {
// Update password!
示例6: loadDatabase
<?php
require 'dbConnector.php';
try {
echo "testing1";
$db = loadDatabase("notes");
echo "testing 2";
echo "testing 3";
} catch (PDOException $ex) {
echo 'Errors!: ' . $ex->getMessage();
die;
}
foreach ($db->query('select username, password from user') as $row) {
echo 'user: ' . $row['username'];
echo ' password: ' . $row['password'];
echo '<br />';
}
/*
$stmt = $db->prepare('select * from table where id=:id and name=:name');
$stmt->bindValue(':id', $id, PDO::PARAM_INT);
$stmt->bindValue(':name', $name, PDO::PARAM_STR);
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
*/
示例7: db_fatal_error
require_once $sourcedir . '/Errors.php';
require_once $sourcedir . '/Load.php';
require_once $sourcedir . '/Security.php';
require_once $sourcedir . '/Subs-Portal.php';
// Using an pre-PHP 5.1 version?
if (@version_compare(PHP_VERSION, '5.1') == -1) {
require_once $sourcedir . '/Subs-Compat.php';
}
// If $maintenance is set specifically to 2, then we're upgrading or something.
if (!empty($maintenance) && $maintenance == 2) {
db_fatal_error();
}
// Create a variable to store some SMF specific functions in.
$smcFunc = array();
// Initate the database connection and define some database functions to use.
loadDatabase();
// Load the settings from the settings table, and perform operations like optimizing.
reloadSettings();
// Clean the request variables, add slashes, etc.
cleanRequest();
$context = array();
// Seed the random generator.
if (empty($modSettings['rand_seed']) || mt_rand(1, 250) == 69) {
smf_seed_generator();
}
// Before we get carried away, are we doing a scheduled task? If so save CPU cycles by jumping out!
if (isset($_GET['scheduled'])) {
require_once $sourcedir . '/ScheduledTasks.php';
AutoTask();
}
// Check if compressed output is enabled, supported, and not already being done.
示例8: session_start
<?php
session_start();
require '../dbConnector.php';
try {
$db = loadDatabase("fhe_ideas");
} catch (PDOException $theError) {
echo 'Error: ' . $theError->getMessage();
die;
}
?>
<html>
<head>
<title> Delete Idea </title>
<script>
// Return to the display page by pushing the cancel button
function cancel() {
window.location="FHE_Ideas.php";
}
</script>
</head>
<body style="background-image:url(Images/IdahoFalls2.png); background-attachment:fixed; background-size: 100% 100% ;background-repeat:no-repeat" >
<h1 style="text-align:center"> Remove an Idea </h1>
<form action="remove_from_database.php" method="POST">
<div style = "margin: 40px; padding:20px; background-color:rgba(250,250,250,0.8); border-radius:25px">
示例9: loadDatabase
<?php
function loadDatabase($db_file)
{
$row = 1;
$d = array();
if (($handle = fopen($db_file, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 100000, ",")) !== FALSE) {
$num = count($data);
$row++;
$vals = array();
for ($c = 0; $c < $num; $c++) {
$vals[$c] = $data[$c];
}
$d[$row] = $vals;
}
fclose($handle);
}
return $d;
}
$d = loadDatabase("dbfile.txt");
$str = "";
foreach ($d as $line) {
if (strlen($str) > 0) {
$str = $str . ",";
}
$str = $str . "{ \"lat\": \"" . $line[0] . "\", \"lng\": \"" . $line[1] . "\", \"zoom\": \"" . $line[2] . "\", \"keyview\": \"" . $line[3] . "\" }";
}
echo "[" . $str . "]";
return;
示例10: address
// add address
$sql = "INSERT INTO address (street, city, state, zip)" . "VALUES(" . '\'' . $_POST['street_address'] . "', '" . $_POST['city'] . "', '" . $_POST['state'] . "', " . $_POST['zip'] . ")";
$_SESSION['insert'] = $sql;
$db = insertDatabase();
$address_id = $db->lastInsertId();
//CREATE user with last created address
$sql = "INSERT INTO user (user_name, email, address_id, phone_number, display_name, password, access_id)" . "VALUES ('{$user_name}', '{$email}', {$address_id}, {$phone_number}, '{$display_name}', '{$password}', 4)";
$_SESSION['insert'] = $sql;
$db = insertDatabase();
//create client connected to last user
$client_user_id = $db->lastInsertId();
$sql = "INSERT INTO client (user_id)" . "VALUES({$client_user_id})";
$_SESSION['insert'] = $sql;
$db = insertDatabase();
require 'db_connection/openshift_db_connection.php';
$employee = loadDatabase();
$statement = $employee->query("SELECT j.id AS job_id, e.id AS employee_id, c.id AS client_id FROM job AS j, employee AS e, client AS c, employeejob AS ej WHERE ej.employee_id=e.id AND ej.job_id=j.id");
$employee = $statement->fetchAll(PDO::FETCH_ASSOC);
for ($i = 0; $i < count($employee); $i++) {
if ($employee[$i]['employee_id']) {
$employee_id = $employee[$i]['employee_id'];
}
if ($employee[$i]['job_id']) {
$job_id = $employee[$i]['job_id'];
}
if ($employee[$i]['client_id']) {
$client_id = $employee[$i]['client_id'];
}
}
echo "employee_id: {$employee_id} <br/>" . "job_id: {$job_id} <br/>" . "client_id: {$client_id} <br/>";
// create job
示例11: loadSettings
//.........这里部分代码省略.........
// 'cur_step_line' => $explode[0],
// 'prev_step_line' => $explode[1],
// 'next_prev_line' => $explode[2],
//);
$_SESSION['do_steps'][$next_step_line] = $step;
}
}
if (isset($_SESSION['convert_parameters']['database_type']) && !isset($convert_data['database_type'])) {
$convert_data['database_type'] = $_SESSION['convert_parameters']['database_type'];
}
if (isset($convert_data['database_type']) && (function_exists($convert_data['database_type'] . '_query') || function_exists($convert_data['database_type'] . '_exec') || $convert_data['database_type'] == 'ado' && class_exists('com'))) {
$convert_dbs = $convert_data['database_type'];
if (isset($convert_data['connect_string'])) {
$connect_string = eval('return "' . $convert_data['connect_string'] . '";');
} elseif (isset($_SESSION['convert_parameters']['connect_string'])) {
$connect_string = $_SESSION['convert_parameters']['connect_string'];
}
if ($convert_dbs == 'odbc') {
$GLOBALS['odbc_connection'] = odbc_connect($connect_string, '', '');
} elseif ($convert_dbs == 'ado') {
$GLOBALS['ado_connection'] = new COM('ADODB.Connection');
$GLOBALS['ado_connection']->Open($connect_string);
register_shutdown_function(create_function('', '$GLOBALS[\'ado_connection\']->Close();'));
}
} elseif (!$command_line && isset($convert_data['database_type'])) {
template_convert_above();
return doStep0('PHP doesn\'t support the database type this converter was written for, \'' . $convert_data['database_type'] . '\'.');
} elseif ($command_line && isset($convert_data['database_type'])) {
return print_error('PHP doesn\'t support the database type this converter was written for, \'' . $convert_data['database_type'] . '\'.', true);
} else {
$convert_dbs = 'smf_db';
}
// Create a connection to the SMF database.
loadDatabase();
db_extend('packages');
// Currently SQLite and PostgreSQL do not have support for cross database work.
if ($command_line && in_array($smcFunc['db_title'], array('SQLite', 'PostgreSQL'))) {
return print_error('The converter detected that you are using ' . $smcFunc['db_title'] . '. The SMF Converter does not currently support this database type.', true);
} elseif (in_array($smcFunc['db_title'], array('SQLite', 'PostgreSQL'))) {
template_convert_above();
return doStep0('The converter detected that you are using ' . $smcFunc['db_title'] . '. The SMF Converter does not currently support this database type.');
}
// Does this converter support the current database type being used?
if ($command_line && !in_array(strtolower($smcFunc['db_title']), $convert_data['database_support'])) {
return print_error('The converter detected that you are using ' . $smcFunc['db_title'] . '. This converter only supports ' . explode(', ', $convert_data['database_support']) . '.', true);
} elseif (!in_array(strtolower($smcFunc['db_title']), $convert_data['database_support'])) {
template_convert_above();
return print_error('The converter detected that you are using ' . $smcFunc['db_title'] . '. This converter only supports ' . explode(', ', $convert_data['database_support']) . '.', true);
}
// UTF8
$charset = findSupportedCharsets();
$charset = array_flip($charset);
$charset = isset($_POST['charsets']) && isset($charset[$_POST['charsets']]) ? $_POST['charsets'] : '';
$charset = !empty($charset) ? $charset : (isset($db_character_set) && preg_match('~^\\w+$~', $db_character_set) === 1 ? $db_character_set : '');
if (!empty($charset)) {
$smcFunc['db_query']('', "SET NAMES {$charset}", 'security_override');
}
if (strpos($db_prefix, '.') === false) {
$to_prefix = is_numeric(substr($db_prefix, 0, 1)) ? $db_name . '.' . $db_prefix : '`' . $db_name . '`.' . $db_prefix;
} else {
$to_prefix = $db_prefix;
}
// Keep in mind our important variables, we don't want them swept away by the code we're running
$smf_db_prefix = $db_prefix;
$smf_db_type = $db_type;
foreach ($convert_data['variable'] as $eval_me) {