本文整理汇总了PHP中open_db函数的典型用法代码示例。如果您正苦于以下问题:PHP open_db函数的具体用法?PHP open_db怎么用?PHP open_db使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了open_db函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate_user
function validate_user($username, $password, $remember_me)
{
$current_page = substr($_SERVER["SCRIPT_NAME"], strrpos($_SERVER["SCRIPT_NAME"], "/") + 1);
open_db();
//Need to sanitize the input
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
if ($username && $password) {
$query = "SELECT * FROM users WHERE username = '{$username}' and (password = '{$password}' OR password = password('{$password}'))";
$result = mysql_query($query);
if (!$result || mysql_num_rows($result) < 1) {
$_SESSION["error"] = "Your login could not be validated";
} else {
$info = mysql_fetch_array($result);
$_SESSION["username"] = $info[username];
$_SESSION["logged_in"] = "Y";
if ($remember_me) {
setcookie("username", $info[username], time() + 60 * 60 * 24 * 90, "/");
setcookie("password", $info[password], time() + 60 * 60 * 24 * 90, "/");
setcookie("remember_me", $remember_me, time() + 60 * 60 * 24 * 90, "/");
}
}
} else {
if ($username && !$password) {
$_SESSION["error"] = "Please enter your password";
} else {
if ($current_page != 'cp' && $current_page != 'cp.php') {
$_SESSION["error"] = "You must be logged in to access this page";
}
}
}
}
示例2: save_xml_tutorial
function save_xml_tutorial(&$file)
{
global $username;
debug_msg("File type is XML");
$tmpfile = $file["tmp_name"];
$filename = $file["name"];
$filepath = "users/{$username}";
debug_msg("Path: {$filepath}");
$pathname = "{$filepath}/{$filename}";
debug_msg("File will be saved as ../{$pathname}");
// Check if file exists and if not, write the data
if (file_exists("../{$pathname}")) {
debug_msg("File exists - temporary storage");
if (!is_dir("../{$filepath}/temp/")) {
mkdir("../{$filepath}/temp/");
}
move_uploaded_file($tmpfile, "../{$filepath}/temp/{$filename}");
$result = false;
} else {
move_uploaded_file($tmpfile, "../{$pathname}");
debug_msg("Move succeeded");
// update database
$filenoext = stripextension($filename);
open_db();
$date = date("Y-m-d");
$sql = "INSERT INTO file (file_date, file_author, file_path, file_name)" . " VALUES ('{$date}','{$username}','{$filepath}','{$filenoext}')" . " ON DUPLICATE KEY UPDATE file_date='{$date}';";
query_db($sql);
$result = $filenoext;
}
return $result;
}
示例3: getGroupProfile
public function getGroupProfile($report_group_id)
{
//error_log(__FILE__.__FUNCTION__.'.$report_group_id: '.$report_group_id);
//$report_group_id = 48; //This will be the selected report group from the drop down
//require "config.php";
$db = open_db();
//Check to see if the user is still logged in
if (isset($_SESSION["user_id"])) {
$params = array("report_group_id" => $report_group_id, "user_id" => $_SESSION["user_id"]);
} else {
//Logged out
header("Location: /login");
//Go to login page
exit;
}
$sth = $db->prepare('
SELECT report_group_id, report_group_name, email_subject_line, report_time_zone, service_addr1, service_addr2, service_addr3,
org_name, mail_address1, mail_address2, mail_city, mail_state, mail_zip, rate_name, rate_notes,
tariff_name, tariff_notes, report_gen_file_name, default_report_file_base_name
FROM report_groups rg, sys_users su, rates r, rate_tariffs rt
WHERE report_group_id = :report_group_id
AND report_group_id IN (SELECT report_group_id FROM link_report_group_sys_user WHERE user_id = :user_id)
AND rg.enabled = TRUE
AND rg.requestor_user_id = su.user_id AND rg.rate_id = r.rate_id AND rt.tariff_id = r.tariff_id
');
$sth->execute($params);
$results = $sth->fetchAll(PDO::FETCH_ASSOC);
$db = null;
return json_encode($results);
}
示例4: planned_delete
function planned_delete($db_array, $path)
{
# used to cleanup outdated mailboxes
$dbhandler = "";
open_db($dbhandler, $db_array);
$request = $dbhandler->query("SELECT * FROM `mailboxlist`");
while ($row = mysqli_fetch_array($request)) {
$current = time();
$current_readable = date('Y-m-d H:i:s', time());
$creation = strtotime($row["creationdate"]);
$creation_readable = $row["creationdate"];
$ttl = $row["duration"] * 60 * 60;
$removing = $creation + $ttl;
$removing_readable = date('Y-m-d H:i:s', $removing);
# converts
if ($current >= $removing) {
# Action for expired mailboxes
$boxname = $row["boxname"];
delete_mailbox($db_array, $boxname, $path);
$to = $row["destination"];
sent_status_mail($to);
#echo "Die Mailbox ".$row["boxname"]." wurde gelöscht!<br \>";
} else {
#echo "for debug purposes<br \>";
}
}
mysqli_close($dbhandler);
}
示例5: update_data
function update_data($sql, $arr)
{
$db = open_db();
try {
$sth = $db->prepare($sql);
for ($i = 0; $i < count($arr); $i++) {
$sth->bindParam($arr[$i][0], $arr[$i][1], $arr[$i][2]);
}
$sth->execute();
} catch (PDOException $e) {
echo "database error: " . $e->getMessage();
}
}
示例6: query_with_row_count
function query_with_row_count($sql)
{
$row_count = 0;
try {
$db = open_db();
foreach ($db->query($sql) as $row) {
// print_r($row);
$row_count++;
}
$db = NULL;
} catch (PDOException $e) {
echo $e->getMessage();
}
$db = NULL;
return $row_count;
}
示例7: overwrite_old_file
function overwrite_old_file($fname)
{
debug_msg("overwrite {$fname}");
global $username;
$filepath = "users/{$username}";
$pathname = "../{$filepath}/{$fname}";
debug_msg("File will be saved as {$pathname}");
// move the file
move_uploaded_file("../{$filepath}/temp/{$filename}", $pathname);
debug_msg("Move succeeded");
// update database
$filenoext = stripextension($fname);
open_db();
$date = date("Y-m-d");
$sql = "INSERT INTO file (file_date, file_author, file_path, file_name)" . " VALUES ('{$date}','{$username}','{$filepath}','{$filenoext}')" . " ON DUPLICATE KEY UPDATE file_date='{$date}';";
query_db($sql);
}
示例8: db_get_records_with_condition
function db_get_records_with_condition($p_dbh, $table_name, $key_field, $key_value, $key_operator = null, $sortby = null, $user = null)
{
$q = "select * from " . $table_name;
if (!empty($key_operator)) {
$q .= " where ";
$q .= "(";
$count = count($key_value);
for ($i = 0; $i < $count; $i++) {
$q .= $key_field . " = ? ";
if ($i < $count - 1) {
$q .= $key_operator . " ";
}
}
$q .= ")";
if ($user != null) {
$key_value[] = $user;
$q .= " AND reviewer = ? ";
}
}
if ($sortby) {
$q .= " order by " . $sortby;
}
try {
$dbh = $p_dbh == null ? open_db() : $p_dbh;
$dbh->beginTransaction();
$sth = $dbh->prepare($q);
$vals = $key_value;
$sth->execute($vals);
$res = $sth->fetchAll(PDO::FETCH_ASSOC);
$dbh->commit();
$dbh = null;
if (count($res) > 0) {
return $res;
} else {
return null;
}
} catch (PDOException $ex) {
$dbh = null;
return null;
}
}
示例9: getPrevBills
public function getPrevBills($report_group_id)
{
//TODO: Check to see if the user is still logged in
error_log(__FILE__ . __LINE__ . '.$report_group_id: ' . $report_group_id . ' - user_id: ' . $_SESSION["user_id"]);
//require "config.php";
$db = open_db();
//Set time zone
/*
$sth = $db->prepare('
SET TIME ZONE :user_tz;
');
if (isset($_SESSION["user_tz"])) //If the user_tz is set
$params = array("user_tz"=>$_SESSION["user_tz"]);
else
$params = array("user_tz"=>'UTC');
$sth->execute($params);
*/
//Get previous bills
$params = array("user_id" => $_SESSION["user_id"], "report_group_id" => $report_group_id);
$sth = $db->prepare("\n SELECT " . $report_group_id . " AS report_group_id, rate_effective_id, date_effective AT TIME ZONE 'UTC' AS bill_start_date,\n (SELECT to_timestamp(param_value) + '23:59:59'::INTERVAL FROM rate_params\n WHERE rate_effective_id = re.rate_effective_id\n AND param_value_id=0) as bill_end_date,\n (SELECT param_value FROM rate_params\n WHERE rate_effective_id = re.rate_effective_id AND param_value_id=1) AS bill_amount\n FROM rates r, rates_effective re\n WHERE r.rate_id = (SELECT rate_id FROM report_groups rg, link_report_group_sys_user lr\n WHERE rg.report_group_id = lr.report_group_id AND\n rg.report_group_id = :report_group_id and user_id = :user_id)\n AND r.rate_id = re.rate_id\n ORDER BY date_effective desc\n ");
$sth->execute($params);
$results = $sth->fetchAll(PDO::FETCH_ASSOC);
//error_log(__FILE__.__LINE__.'$params: '.print_r($params, true));
//error_log(__FILE__.__LINE__.'$results: '.print_r($results, true));
//Perform formatting
//$fmt = new NumberFormatter( $_SESSION["user_locale"], NumberFormatter::CURRENCY );
//Properly format the results
$final = array();
foreach ($results as $result) {
$result['bill_start_date'] = date("c", strtotime($result['bill_start_date']));
//ISO 8601
$result['bill_end_date'] = date("c", strtotime($result['bill_end_date']));
//ISO 8601
$final[] = $result;
}
echo json_encode($final);
}
示例10: init
function init(&$db, $checkSession = NULL)
{
$ok = TRUE;
// Set timezone
if (!ini_get('date.timezone')) {
date_default_timezone_set('UTC');
}
// Set session cookie path
ini_set('session.cookie_path', getAppPath());
// Open session
session_name(SESSION_NAME);
session_start();
if (!is_null($checkSession) && $checkSession) {
$ok = isset($_SESSION['consumer_key']) && isset($_SESSION['resource_id']) && isset($_SESSION['user_consumer_key']) && isset($_SESSION['user_id']) && isset($_SESSION['isStudent']);
}
if (!$ok) {
$_SESSION['error_message'] = 'Unable to open session.';
} else {
// Open database connection
$db = open_db(!$checkSession);
$ok = $db !== FALSE;
if (!$ok) {
if (!is_null($checkSession) && $checkSession) {
// Display a more user-friendly error message to LTI users
$_SESSION['error_message'] = 'Unable to open database.';
}
} else {
if (!is_null($checkSession) && !$checkSession) {
// Create database tables (if needed)
$ok = init_db($db);
// assumes a MySQL/SQLite database is being used
if (!$ok) {
$_SESSION['error_message'] = 'Unable to initialise database.';
}
}
}
}
return $ok;
}
示例11: open_db
<h1>Full Program</h1>
<?php
require_once "lib/app.php";
$db = open_db($db_address_abs);
require "data/events.php";
$fmt = 'H:i';
$cur = NULL;
$all = array_merge($presentations, $breaks);
function cmp($a, $b)
{
$fmt = 'Y-m-d\\TH:i:s';
return strcmp($a->start->format($fmt), $b->start->format($fmt));
}
usort($all, "cmp");
foreach ($all as $p) {
#print "//{$p->id}";
#if (!$p->is_plenary) { continue; }
$day = $p->start->format('l jS \\of F Y');
if (!($day == $cur)) {
if (!is_null($cur)) {
print "</ul>\n";
}
print "<h2>{$day}</h2>\n";
print "<ul class='fullprog'>\n";
$cur = $day;
}
#print "<!-- " . $day . " " . $cur . "-->\n";
print <<<EOT
示例12: require_once
<?
require_once("../_shared/config.inc.php");
include_once("../_shared/func.inc.php");
open_db($db_host,$db_user,$db_passw,$datbase);
$data = get_row("referenz","name,pos,imgs","id='".$id."'");
if ($f_cancel) {
echo "<script language=\"javascript\">window.close(this)</script>";
exit;
}
if ($f_rem) {
if ($data['imgs']) {
$pics = explode("#",$data['imgs']);
for ($x = 0; $x < 6; $x++) {
if ($pics[$x] != "---") {
unlink($img_ref.$id."_".$x."_sm.jpg");
unlink($img_ref.$id."_".$x."_lg.jpg");
}
}
}
remove_data("referenz","id=".$id);
update_data("referenz","pos=pos-1","pos>".$data['pos']);
mysql_close;
echo "<script language=\"javascript\">window.opener.location.href='list.php'</script>";
echo "<script language=\"javascript\">window.close(this)</script>";
}
echo "<html>\n";
echo "<head>\n";
示例13: put
function put()
{
require 'config.php';
$request = check_and_clean_json('collector_id');
if (EC_DEBUG) {
error_log(__FILE__ . __LINE__ . ":REST:get_new_device_id:REQUEST" . print_r($request, true));
}
if ($request != null) {
//Check for valid inputs
if (!$request->collector_id) {
error_log(__FILE__ . __LINE__ . ":REST:get_new_device_id:No collector_id provided");
echo "RESTRICTED SYSTEM";
return;
}
if (!$request->device_type_id) {
error_log(__FILE__ . __LINE__ . ":REST:get_new_device_id:No device_type_id provided");
echo "RESTRICTED SYSTEM";
return;
}
if (!$request->device_name && strlen($request->device_name) > 0) {
error_log(__FILE__ . __LINE__ . ":REST:get_new_device_id:No device_name provided");
echo "RESTRICTED SYSTEM";
return;
}
}
$conn = open_db();
//Verify that a proper collector_id and device_type_id was supplied
$sth = $conn->prepare('
SELECT owner_user_id FROM device_types dt, collector_types ct, collectors c
WHERE
ct.collector_type_id = dt.collector_type_id AND
c.collector_type_id = ct.collector_type_id AND
c.collector_id = :collector_id AND
device_type_id = :device_type_id;
');
if (EC_DEBUG) {
error_log(__FILE__ . __LINE__ . ":REST:get_new_device_id:DATA: " . $request->collector_id . " - " . $request->device_type_id . " - " . $request->device_name);
}
$sth->execute(array('collector_id' => $request->collector_id, 'device_type_id' => $request->device_type_id));
$owner_user_id = $sth->fetchColumn();
if (EC_DEBUG) {
error_log(__FILE__ . __LINE__ . ":REST:get_new_device_id:owner_user_id: " . $owner_user_id);
}
if ($owner_user_id) {
//Valid device type for the collector type if the query returns $owner_user_id
//Insert into devices and get new device_id
$sth = $conn->prepare('
SELECT device_id FROM devices WHERE collector_id = :collector_id AND device_name = :device_name;
');
$sth->execute(array('collector_id' => $request->collector_id, 'device_name' => $request->device_name));
$device_id = $sth->fetchColumn();
if (!$device_id) {
//if device does not already exist
//Insert row into devices table
$sth = $conn->prepare('
INSERT INTO devices (device_name, device_type_id, collector_id, device_comm_data1, enabled, gmt_last_config_update)
VALUES(:device_name, :device_type_id, :collector_id, :device_comm_data1, true, now()) RETURNING device_id;
');
$sth->execute(array('device_name' => $request->device_name, 'device_type_id' => $request->device_type_id, 'collector_id' => $request->collector_id, 'device_comm_data1' => $request->device_comm_data1));
//error_log(print_r($sth->errorInfo(), true));
$device_id = $sth->fetchColumn();
//Get the new device_id
//Give the sys admin access to the new device
$sth = $conn->prepare('
INSERT INTO link_users_devices (user_id, device_id) VALUES (1, :device_id)
');
$sth->execute(array('device_id' => $device_id));
//Give the creator access to the new device
$sth = $conn->prepare('
INSERT INTO link_users_devices(user_id, device_id)
VALUES(:user_id, :device_id);
');
$sth->execute(array('user_id' => $owner_user_id, 'device_id' => $device_id));
} else {
error_log("REST:get_new_device_id:ERROR: Device already exists");
}
//Create the response
$response = array('device_id' => $device_id, 'enabled' => true);
if (EC_DEBUG) {
error_log(__FILE__ . __LINE__ . ":REST:get_new_device_id:RESPONSE1: " . print_r($response, true));
}
//Send the response
echo json_encode($response);
} else {
//Error or other problem
//Create the response
$response = array('device_id' => -1, 'enabled' => false);
error_log(__FILE__ . __LINE__ . "REST:get_new_device_id:RESPONSE2: " . print_r($response, true));
//Send the response
echo json_encode($response);
}
}
示例14: db_save_session
function db_save_session($p_dbh, $session_id, $username, $account_id)
{
$q_insert = "insert into session (id, username, account_id, created_on) values (?,?,?,NOW())";
$q_update = "update session set username=?, account_id=?, created_on=NOW() where id=?";
try {
$dbh = $p_dbh == null ? open_db() : $p_dbh;
$sess = db_get_session($dbh, $session_id);
if ($sess === null) {
$q = $q_insert;
$vals = array($session_id, $username, $account_id);
} else {
$q = $q_update;
$vals = array($username, $account_id, $session_id);
}
$dbh->beginTransaction();
$sth = $dbh->prepare($q);
$sth->execute($vals);
$dbh->commit();
$dbh = null;
return true;
} catch (PDOException $ex) {
echo "Error Message: " . $ex->getMessage();
if ($dbh) {
$dbh->rollBack();
$dbh = null;
}
return false;
}
}
示例15: session_start
<?php
session_start();
/*print_r($_POST);*/
if (!isset($_SESSION['username'])) {
json_encode(array('status' => 'error', 'error' => 'not logged in', 'code' => 500));
exit;
}
require 'database.php';
$dbconn = open_db();
$action = $_POST['action'];
// Here I have ajax file which can handle any ajax calls based on aciton like delete-device history
switch ($action) {
case "delete-device":
$userId = $_POST['userid'];
$getDev = "SELECT devid FROM devices WHERE users_id = " . $userId . " AND status = 1";
/*$query = "UPDATE devices SET status = 0 WHERE id=$id";
if(mysqli_query($dbconn, $query)) {
$deleted = true;
}*/
$query = "UPDATE mob_signal SET status = 0 WHERE devid=({$getDev})";
if (mysqli_query($dbconn, $query)) {
$deleted = true;
}
$deleted = true;
if (isset($deleted) && ($deleted = true)) {
echo json_encode(array('status' => 'ok', 'msg' => "You have deleted Successfully"));
} else {
echo json_encode(array('status' => 'error', 'code' => 500));
}