本文整理汇总了PHP中get_db_connection函数的典型用法代码示例。如果您正苦于以下问题:PHP get_db_connection函数的具体用法?PHP get_db_connection怎么用?PHP get_db_connection使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_db_connection函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: set_active_state
function set_active_state($vermutung_id, $new_state)
{
$connection = get_db_connection();
$update_query = sprintf("UPDATE vermutung SET active = '%s' WHERE id = '%s'", mysql_real_escape_string($new_state), mysql_real_escape_string($vermutung_id));
$result = mysql_query($update_query);
mysql_close($connection);
return $result;
}
示例2: exec_query
function exec_query($sql)
{
static $conn = null;
if ($conn == null) {
$conn = get_db_connection();
}
if (mysql_query($sql, $conn) === FALSE) {
error_out(500, "MySQL Error: " . mysql_error($conn) . "; running query: {$sql}");
}
}
示例3: users_getById
function users_getById($id)
{
$db = get_db_connection();
$tmp = $db->query("SELECT * from users WHERE id = {$id}");
if ($tmp->num_rows != 0) {
$user = $tmp->fetch_assoc();
} else {
$user = false;
}
return $user;
}
示例4: list_all_hackers
function list_all_hackers()
{
$db = get_db_connection();
$hackers = $db->select('parameter_tampering', '*');
$output = "<pre><table>";
foreach ($hackers as $hacker) {
$output .= "<tr><td>" . $hacker["id"] . ". " . $hacker["name"] . " booked " . $hacker["number_of_tickets"] . " and paid " . $hacker["amount"] . "\$ . (Email: " . $hacker["email"] . " ) </td></tr>";
}
$output .= "</table></pre>";
return $output;
}
示例5: photos_getByUser
function photos_getByUser($id)
{
$db = get_db_connection();
$tmp = $db->query("SELECT * FROM photo WHERE user_id = {$id}");
if ($tmp->num_rows != 0) {
while ($row = $tmp->fetch_assoc()) {
$photo[] = $row;
}
} else {
$photo = [];
}
return $photo;
}
示例6: albums_getById
function albums_getById($id)
{
$db = get_db_connection();
if (is_null($id)) {
return false;
}
$tmp = $db->query("SELECT * FROM albums WHERE id = {$id}");
if ($tmp->num_rows != 0) {
$a = $tmp->fetch_assoc();
} else {
$a = false;
}
return $a;
}
示例7: getProjectsByTech
function getProjectsByTech($techID)
{
try {
$db = get_db_connection();
$stmt = $db->prepare("SELECT projects.* FROM projects\n JOIN site_techs ON projects.project_id = site_techs.project_id\n JOIN techniques ON site_techs.tech_id = techniques.tech_id\n WHERE techniques.tech_id = ?;");
$stmt->bindParam(1, $techID, PDO::PARAM_INT);
$stmt->execute();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$this->name[] = $row['name'];
$this->url[] = $row['url'];
$this->github[] = $row['github'];
$this->projectID[] = $row['project_id'];
$this->imagePath[] = $row['image_url'];
}
} catch (Exception $e) {
echo "Fehler beim Verbinden zur Datenbank";
}
}
示例8: save
/**
* Will attempt to save the current record
* An INSERT will be performed if the primary key for $this is not already populated
* An UPDATE will be performed otherwise
* Various options will be available within the function --> still under construction(sanitize,quote,includeEmpties,includeNulls)
* @param string/array $listOfFields --> determines which fields are to be saved (single fieldname string or indexed array of fieldnames)
* @return bool
*/
public function save($listOfFields = "*")
{
//If user passes *, then we'll attempt to save all columns (except for the primary key) to the database
if ($listOfFields == '*') {
$listOfFields = $this->allFieldsWithoutKeys;
} elseif (!is_array($listOfFields)) {
$listOfFields = array((string) $listOfFields);
}
$db = get_db_connection();
//Create an assoc array of all the values we're about to save
$nameValuePairs = $this->GetFieldsAsAssocArray($listOfFields);
$field_values = array_values($nameValuePairs);
$field_names = array_keys($nameValuePairs);
array_unshift($field_values, $this->GetBoundParamTypeString($field_names));
if (empty($this->test_pk)) {
//INSERT new record when this class's primary key property is empty
$sql = 'INSERT INTO `test`' . ' (`' . implode('`, `', $field_names) . '`)' . ' VALUES (' . str_repeat('?,', count($field_names) - 1) . '?) ';
$rs = $db->query($sql, null, null, $field_values);
if ($rs) {
$this->test_pk = $db->insertID();
return true;
} else {
return false;
}
} else {
//UPDATE existing record based on this class's primary key
$field_values[0] = $field_values[0] . $this->GetBoundParamTypeString(array('test_pk'));
$sql = 'UPDATE `test` SET ' . '`' . implode('`=?, `', $field_names) . '`=? ' . ' WHERE `test_pk` = ?';
$field_values[] = $this->test_pk;
$rs = $db->query($sql, null, null, $field_values);
if ($rs) {
$this->test_pk = $db->insertID();
return true;
} else {
return false;
}
}
}
示例9: get_db_connection
function &default_context($make_session)
{
/*
Argument is a boolean value that tells the function whether to make a
session or not.
*/
$db =& get_db_connection();
/* change character set to utf8 */
$db->query("SET NAMES utf8mb4");
//$db->query("SET CHARACTER SET 'utf8'");
$user = null;
$type = get_preferred_type($_GET['type'] ? $_GET['type'] : $_SERVER['HTTP_ACCEPT']);
if ($type == 'text/html' && $make_session) {
// get the session user if there is one
session_set_cookie_params(86400 * 31, get_base_dir(), null, false, true);
session_start();
$user = cookied_user($db);
}
// Smarty is created last because it needs $_SESSION populated
$sm =& get_smarty_instance($user);
$ctx = new Context($db, $sm, $user, $type);
return $ctx;
}
示例10: get_db_connection
<?php
require_once '../admin/config.php';
function get_db_connection()
{
$db = new pdo(DB_DRIVER . ":dbname=" . DB_NAME . ";charset=utf8;host=" . DB_HOST, DB_USER, DB_PASS);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $db;
}
function __autoload($class)
{
require '../classes/class.' . $class . '.php';
}
$techID = $_POST['techID'];
try {
$db = get_db_connection();
$stmt = $db->prepare("SELECT projects.* FROM projects\n JOIN site_techs ON projects.project_id = site_techs.project_id\n JOIN techniques ON site_techs.tech_id = techniques.tech_id\n WHERE techniques.tech_id = ?;");
$stmt->bindParam(1, $techID, PDO::PARAM_INT);
$stmt->execute();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$name[] = $row['name'];
$url[] = $row['url'];
$github[] = $row['github'];
$projectID[] = $row['project_id'];
$imagePath[] = $row['image_url'];
}
} catch (Exception $e) {
echo "Fehler beim Verbinden zur Datenbank";
}
$countTechs = count($name);
echo "Anzahl: {$countTechs}<br>";
示例11: ini_set
<?php
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . '../lib');
require_once 'init.php';
require_once 'data.php';
require_once 'output.php';
list($response_format, $response_mime_type) = parse_format($_GET['format'], 'html');
$dbh =& get_db_connection();
if (get_request_user()) {
// auth stuff here
}
$dbh = null;
$sm = get_smarty_instance();
if (get_request_user()) {
// secure template vars here
}
header("Content-Type: {$response_mime_type}; charset=UTF-8");
print $sm->fetch("index.{$response_format}.tpl");
示例12: urlencode
// already URL encoded
$location = $_POST['location'];
// user friendly display name of user location
if ($location != "") {
$location = urlencode($location);
$place_name = urldecode($location);
// geocode
try {
$location_XML = yahoo_geo($_REQUEST['location']);
$location = $location_XML['Latitude'] . "," . $location_XML['Longitude'];
$location_latitude = $location_XML['Latitude'];
$location_longitude = $location_XML['Longitude'];
// get event number
$event_index = $_POST['event_index'];
if ($event_index > 0) {
$conn = get_db_connection($db_user, $db_passwd, $db_name);
$event_label = $event_index;
$latitudes[$event_index] = $location_latitude;
$longitudes[$event_index] = $location_longitude;
$sql_result = save_vote($location_latitude, $location_longitude, $event_label);
//
$db_status_close = close_db_connection($conn);
} else {
$event_label = "";
}
//
$map_click_X = $_POST['map_x'];
$map_click_Y = $_POST['map_y'];
} catch (exception $e) {
$location_latitude = 0;
$location_longitude = 0;
示例13: get_db_connection
<?php
require 'db.php';
$conn = get_db_connection();
if ($conn === false) {
?>
<h1>Error connecting to database</h1>
<?php
die;
}
/* GET READY */
/* PUT YOUR CODE HERE */
?>
<form method="post">
<textarea name="content"></textarea>
<input type="text" name="author" placeholder="Your Name" />
<button type="submit">Submit Post</button>
</form>
示例14: createFormElements
function createFormElements($report_elements)
{
global $bDebug;
if (!is_array($report_elements)) {
return;
}
unset($form_elements);
foreach ($report_elements as $key => $value) {
$elemName = $key;
$elemLabel = $value["label"];
$elemType = $value["type"];
//$arr_params = Array("dbLink"=>get_db_connection(), "bDebug"=>$bDebug );
$arr_params = get_db_connection();
$elemValuesFunction = $value["values_func"];
if ($elemValuesFunction != NULL) {
$elemValues = @call_user_func_array($elemValuesFunction, $arr_params);
//log_err("elemValuesFunction : $elemValuesFunction");
} else {
$elemValues = $value["values"];
}
$elemDefault = $value["default"];
$elemRequired = $value["required"];
switch ($elemType) {
case "date":
$strControl = createDateControl("document._FRM", $elemName, $elemDefault, $elemRequired);
break;
case "select":
$strControl = createSelect($elemName, $elemValues, $elemDefault, $script, $class_style);
break;
case "multiselect":
$strControl = createMultipleSelect($elemName, $elemValues, $elemDefault, $script, $class_style);
break;
case "input":
$strControl = createTextField($elemName, $elemValues, $elemLabel, $class);
break;
case "checkbox":
$strControl = createCheckBox($elemName, $elemValues, $elemLabel, $elemDefault);
break;
default:
$strControl = "cant create control, elem type {$elemType} undefined.";
break;
}
$form_elements[] = array("label" => $elemLabel, "required" => $elemRequired, "control" => $strControl);
}
return $form_elements;
}
示例15: get_database
function get_database($dbname)
{
$conn = get_db_connection();
return $conn->{$dbname};
}