本文整理汇总了PHP中pdo_connect函数的典型用法代码示例。如果您正苦于以下问题:PHP pdo_connect函数的具体用法?PHP pdo_connect怎么用?PHP pdo_connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pdo_connect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveMedia
function saveMedia($bin_name, $base_imgpath)
{
$folder_path = $base_imgpath . '/' . $bin_name . '/';
try {
$dbh = pdo_connect();
$sql = 'SELECT COUNT(DISTINCT `id`) FROM `' . $bin_name . '_media`';
$rec = $dbh->prepare($sql);
$rec->execute();
$row = $rec->fetch(PDO::FETCH_NUM);
echo 'This bin: ' . $bin_name . ' has ' . $row[0] . ' media files.' . PHP_EOL;
$sql = 'SELECT DISTINCT `id`, `media_url_https` FROM `' . $bin_name . '_media`';
$rec2 = $dbh->prepare($sql);
$rec2->execute();
$i = 1;
while ($row = $rec2->fetch(PDO::FETCH_ASSOC)) {
echo $i . '. ';
saveMedia2File($folder_path, $row['media_url_https'], $row['id']);
$i++;
}
unset($dbh);
} catch (PDOException $e) {
$errorMessage = $e->getCode() . ': ' . $e->getMessage();
return $errorMessage;
}
}
示例2: get_related_dates
function get_related_dates($projectname, $basedate)
{
include "cdash/config.php";
require_once "cdash/pdo.php";
$dates = array();
$db = pdo_connect("{$CDASH_DB_HOST}", "{$CDASH_DB_LOGIN}", "{$CDASH_DB_PASS}");
pdo_select_db("{$CDASH_DB_NAME}", $db);
$dbQuery = pdo_query("SELECT nightlytime FROM project WHERE name='{$projectname}'");
if (pdo_num_rows($dbQuery) > 0) {
$project = pdo_fetch_array($dbQuery);
$nightlytime = $project['nightlytime'];
//echo "query result nightlytime: " . $nightlytime . "<br/>";
} else {
$nightlytime = "00:00:00";
//echo "default nightlytime: " . $nightlytime . "<br/>";
}
if (!isset($basedate) || strlen($basedate) == 0) {
$basedate = gmdate(FMT_DATE);
}
// Convert the nightly time into GMT
$nightlytime = gmdate(FMT_TIME, strtotime($nightlytime));
$nightlyhour = time2hour($nightlytime);
$nightlyminute = time2minute($nightlytime);
$nightlysecond = time2second($nightlytime);
$basemonth = date2month($basedate);
$baseday = date2day($basedate);
$baseyear = date2year($basedate);
$dates['nightly+2'] = gmmktime($nightlyhour, $nightlyminute, $nightlysecond, $basemonth, $baseday + 2, $baseyear);
$dates['nightly+1'] = gmmktime($nightlyhour, $nightlyminute, $nightlysecond, $basemonth, $baseday + 1, $baseyear);
$dates['nightly-0'] = gmmktime($nightlyhour, $nightlyminute, $nightlysecond, $basemonth, $baseday, $baseyear);
$dates['nightly-1'] = gmmktime($nightlyhour, $nightlyminute, $nightlysecond, $basemonth, $baseday - 1, $baseyear);
$dates['nightly-2'] = gmmktime($nightlyhour, $nightlyminute, $nightlysecond, $basemonth, $baseday - 2, $baseyear);
// Snapshot of "now"
//
$currentgmtime = time();
$currentgmdate = gmdate(FMT_DATE, $currentgmtime);
// Find the most recently past nightly time:
//
$todaymonth = date2month($currentgmdate);
$todayday = date2day($currentgmdate);
$todayyear = date2year($currentgmdate);
$currentnightly = gmmktime($nightlyhour, $nightlyminute, $nightlysecond, $todaymonth, $todayday, $todayyear);
while ($currentnightly > $currentgmtime) {
$todayday = $todayday - 1;
$currentnightly = gmmktime($nightlyhour, $nightlyminute, $nightlysecond, $todaymonth, $todayday, $todayyear);
}
$dates['now'] = $currentgmtime;
$dates['most-recent-nightly'] = $currentnightly;
$dates['today_utc'] = $currentgmdate;
$dates['basedate'] = gmdate(FMT_DATE, $dates['nightly-0']);
// CDash equivalent of DART1's "last rollup time"
if ($dates['basedate'] === $dates['today_utc']) {
// If it's today, it's now:
$dates['last-rollup-time'] = $dates['now'];
} else {
// If it's not today, it's the nightly time on the basedate:
$dates['last-rollup-time'] = $dates['nightly-0'];
}
return $dates;
}
示例3: processLoad
/**
* Process the query
* @param $user the user to look for
* @param $password the user password
* @param $id the id in the hatting table
*/
function processLoad($user, $password, $id)
{
// Connect to the database
$pdo = pdo_connect();
getUser($pdo, $user, $password);
$idQ = $pdo->quote($id);
$query = "SELECT name, uri, type, x, y, rotation, scale, color, feather from hatting where id={$idQ}";
$rows = $pdo->query($query);
if ($row = $rows->fetch()) {
// We found the record in the database
echo "<hatter status=\"yes\">";
$uri = $row['uri'];
$x = $row['x'];
$y = $row['y'];
$angle = $row['rotation'];
$scale = $row['scale'];
$color = $row['color'];
$hat = $row['type'];
$feather = $row['feather'] == 1 ? "yes" : "no";
echo "<hatting uri=\"{$uri}\" x=\"{$x}\" y=\"{$y}\" angle=\"{$angle}\" scale=\"{$scale}\" color=\"{$color}\" type=\"{$hat}\" feather=\"{$feather}\" />\r\n";
echo "</hatter>";
exit;
}
echo '<hatter status="no" msg="image" />';
}
示例4: processXml
/**
* Process the XML query
* @param $xmltext the provided XML
*/
function processXml($xmltext)
{
// Load the XML
$xml = new XMLReader();
if (!$xml->XML($xmltext)) {
echo '<hatter status="no" msg="invalid XML" />';
exit;
}
// Connect to the database
$pdo = pdo_connect();
// Read to the start tag
while ($xml->read()) {
if ($xml->nodeType == XMLReader::ELEMENT && $xml->name == "hatter") {
// We have the hatter tag
$magic = $xml->getAttribute("magic");
if ($magic != "NechAtHa6RuzeR8x") {
echo '<hatter status="no" msg="magic" />';
exit;
}
$user = $xml->getAttribute("user");
$password = $xml->getAttribute("pw");
$userid = getUser($pdo, $user, $password);
// Read to the hatting tag
while ($xml->read()) {
if ($xml->nodeType == XMLReader::ELEMENT && $xml->name == "hatting") {
$name = $xml->getAttribute("name");
$uri = $xml->getAttribute("uri");
$x = $xml->getAttribute("x");
$y = $xml->getAttribute("y");
$angle = $xml->getAttribute("angle");
$scale = $xml->getAttribute("scale");
$color = $xml->getAttribute("color");
$hat = $xml->getAttribute("hat");
$feather = $xml->getAttribute("feather") == "yes" ? 1 : 0;
$nameQ = $pdo->quote($name);
$uriQ = $pdo->quote($uri);
// Checks
if (!is_numeric($x) || !is_numeric($y) || !is_numeric($angle) || !is_numeric($scale) || !is_numeric($color) || !is_numeric($hat)) {
echo '<hatter status="no" msg="invalid" />';
exit;
}
$query = <<<QUERY
REPLACE INTO hatting(name, userid, uri, type, x, y, rotation, scale, color, feather)
VALUES({$nameQ}, '{$userid}', {$uriQ}, {$hat}, {$x}, {$y}, {$angle}, {$scale}, {$color}, {$feather})
QUERY;
if (!$pdo->query($query)) {
echo '<hatter status="no" msg="insertfail">' . $query . '</hatter>';
exit;
}
echo '<hatter status="yes"/>';
exit;
}
}
}
}
echo '<hatter save="no" msg="invalid XML" />';
}
示例5: pdo_select_db
function pdo_select_db($database, $link_identifier = null)
{
global $CDASH_DB_HOST, $CDASH_DB_LOGIN, $CDASH_DB_PASS, $cdash_database_connection;
if (!is_null($link_identifier) and $link_identifier instanceof CDash\Database and $cdash_database_connection->getDatabaseName() === $database) {
$cdash_database_connection = $link_identifier;
} else {
$cdash_database_connection = pdo_connect($CDASH_DB_HOST, $CDASH_DB_LOGIN, $CDASH_DB_PASS, $database);
}
return true;
}
示例6: updateroomstatus
/**
* Ask the database for the user ID. If the user exists, the password
* must match.
* @param $pdo PHP Data Object
* @param $user The user name
* @param $password Password
* @return id if successful or exits if not
*/
function updateroomstatus($stat, $email, $roomNum, $location)
{
// Connect to the database
$pdo = pdo_connect();
$sql = <<<SQL
UPDATE conferenceRooms
SET status=?,roomEmail=?
WHERE confRm=?
SQL;
$statement = $pdo->prepare($sql);
$statement->execute(array($stat, $email, $roomNum, $location));
}
示例7: get_link_identifier
/** */
function get_link_identifier($link_identifier = NULL)
{
global $CDASH_DB_TYPE;
global $last_link;
if (isset($link_identifier)) {
return $link_identifier;
}
if (isset($last_link)) {
return $last_link;
}
$last_link = pdo_connect();
return $last_link;
}
示例8: processDelete
/**
* Process the query
* @param $user the user to look for
* @param $password the user password
* @param $id the id in the hatting table
*/
function processDelete($user, $password, $id)
{
// Connect to the database
$pdo = pdo_connect();
$idQ = $pdo->quote($id);
getUser($pdo, $user, $password);
$query = "DELETE from hatting where id={$idQ}";
if (!$pdo->query($query)) {
echo '<hatter status="no" msg="deletefail">' . $query . '</hatter>';
exit;
}
echo '<hatter status="yes"/>';
$pdo = null;
}
示例9: process
/**
* Process the query
* @param $user the user to look for
* @param $password the user password
*/
function process($user, $password)
{
// Connect to the database
$pdo = pdo_connect();
$userid = getUser($pdo, $user, $password);
$query = "select id, name from hatting where userid='{$userid}'";
$rows = $pdo->query($query);
echo "<hatter status=\"yes\">";
foreach ($rows as $row) {
$id = $row['id'];
$name = $row['name'];
echo "<hatting id=\"{$id}\" name=\"{$name}\" />\r\n";
}
echo "</hatter>";
}
示例10: processLoad
/**
* Process the query
* @param $user the user to look for
* @param $password the user password
* @param $id the id in the hatting table
*/
function processLoad()
{
$pdo = pdo_connect();
$query = "SELECT * from conferenceRooms";
$statement = $pdo->prepare($query);
$statement->execute();
$activities = $statement->fetchAll();
$x = 0;
foreach ($activities as $row) {
$result[$x] = array($row['location'], $row['confRm'], $row['capacity'], $row['polycomExt'], $row['avResources'], $row['ownership'], $row['notes'], $row['status'], $row['floor'], $row['roomEmail']);
$x = $x + 1;
}
echo json_encode($result);
// echo json_encode($result);
exit;
}
示例11: insertroom
function insertroom($location, $room, $floor, $status, $email, $owner, $resources, $capacity)
{
$poly = "";
$note = "";
$sql = <<<SQL
INSERT INTO conferenceRooms(location,confRm,capacity,polycomExt,avResources,ownership,notes,status,floor,roomEmail)
VALUES (?,?,?,?,?,?,?,?,?,?)
SQL;
$pdo = pdo_connect();
$statement = $pdo->prepare($sql);
if ($statement->execute(array($location, $room, $capacity, $poly, $resources, $owner, $note, $status, $floor, $email))) {
return true;
} else {
return false;
}
}
示例12: get_dashboard_JSON
function get_dashboard_JSON($projectname, $date, &$response)
{
include "cdash/config.php";
require_once "cdash/pdo.php";
$projectid = get_project_id($projectname);
if ($projectid == -1) {
return;
}
$db = pdo_connect("{$CDASH_DB_HOST}", "{$CDASH_DB_LOGIN}", "{$CDASH_DB_PASS}");
if (!$db) {
echo "Error connecting to CDash database server<br>\n";
exit(0);
}
if (!pdo_select_db("{$CDASH_DB_NAME}", $db)) {
echo "Error selecting CDash database<br>\n";
exit(0);
}
$project = pdo_query("SELECT * FROM project WHERE id='{$projectid}'");
if (pdo_num_rows($project) > 0) {
$project_array = pdo_fetch_array($project);
} else {
$project_array = array();
$project_array["cvsurl"] = "unknown";
$project_array["bugtrackerurl"] = "unknown";
$project_array["documentationurl"] = "unknown";
$project_array["homeurl"] = "unknown";
$project_array["googletracker"] = "unknown";
$project_array["name"] = $projectname;
$project_array["nightlytime"] = "00:00:00";
}
list($previousdate, $currentstarttime, $nextdate) = get_dates($date, $project_array["nightlytime"]);
$response['datetime'] = date("l, F d Y H:i:s", time());
$response['date'] = $date;
$response['unixtimestamp'] = $currentstarttime;
$response['startdate'] = date("l, F d Y H:i:s", $currentstarttime);
$response['svn'] = make_cdash_url(htmlentities($project_array["cvsurl"]));
$response['bugtracker'] = make_cdash_url(htmlentities($project_array["bugtrackerurl"]));
$response['googletracker'] = htmlentities($project_array["googletracker"]);
$response['documentation'] = make_cdash_url(htmlentities($project_array["documentationurl"]));
$response['projectid'] = $projectid;
$response['projectname'] = $project_array["name"];
$response['projectname_encoded'] = urlencode($project_array["name"]);
$response['projectpublic'] = $project_array["public"];
$response['previousdate'] = $previousdate;
$response['nextdate'] = $nextdate;
$response['logoid'] = getLogoID($projectid);
if (empty($project_array["homeurl"])) {
$response['home'] = "index.php?project=" . urlencode($project_array["name"]);
} else {
$response['home'] = make_cdash_url(htmlentities($project_array["homeurl"]));
}
if ($CDASH_USE_LOCAL_DIRECTORY && file_exists("local/models/proProject.php")) {
include_once "local/models/proProject.php";
$pro = new proProject();
$pro->ProjectId = $projectid;
$response['proedition'] = $pro->GetEdition(1);
}
$userid = 0;
if (isset($_SESSION['cdash'])) {
$userid = $_SESSION['cdash']['loginid'];
// Is the user super administrator
$userquery = pdo_query("SELECT admin FROM " . qid('user') . " WHERE id='{$userid}'");
$user_array = pdo_fetch_array($userquery);
$response['admin'] = $user_array[0];
// Is the user administrator of the project
$userquery = pdo_query("SELECT role FROM user2project WHERE userid=" . qnum($userid) . " AND projectid=" . qnum($projectid));
$user_array = pdo_fetch_array($userquery);
$response['projectrole'] = $user_array[0];
}
$response['userid'] = $userid;
}
示例13: deleteGame
function deleteGame($username, $title)
{
$data = array();
$connection = pdo_connect();
if (doesTitleExist($username, $title)) {
$query = <<<SQL
DELETE
FROM SAVEGAMES
WHERE Username = ? AND Title = ?
SQL;
$statement = $connection->prepare($query);
$result = $statement->execute(array($username, $title));
if ($result == true) {
$data['delete'] = true;
} else {
$data['delete'] = false;
$data['error'] = "Couldn't delete";
}
} else {
$data['delete'] = false;
$data['error'] = "Title not valid";
}
echo json_encode($data);
}
示例14: echo_main_dashboard_JSON
function echo_main_dashboard_JSON($project_instance, $date)
{
$start = microtime_float();
$noforcelogin = 1;
include_once dirname(dirname(dirname(__DIR__))) . '/config/config.php';
require_once 'include/pdo.php';
include 'public/login.php';
include_once 'models/banner.php';
include_once 'models/build.php';
include_once 'models/subproject.php';
$response = array();
$db = pdo_connect("{$CDASH_DB_HOST}", "{$CDASH_DB_LOGIN}", "{$CDASH_DB_PASS}");
if (!$db) {
$response['error'] = 'Error connecting to CDash database server';
echo json_encode($response);
return;
}
if (!pdo_select_db("{$CDASH_DB_NAME}", $db)) {
$response['error'] = 'Error selecting CDash database';
echo json_encode($response);
return;
}
$projectid = $project_instance->Id;
$project = pdo_query("SELECT * FROM project WHERE id='{$projectid}'");
if (pdo_num_rows($project) > 0) {
$project_array = pdo_fetch_array($project);
$projectname = $project_array['name'];
if (isset($project_array['testingdataurl']) && $project_array['testingdataurl'] != '') {
$testingdataurl = make_cdash_url(htmlentities($project_array['testingdataurl']));
}
} else {
$response['error'] = "This project doesn't exist. Maybe the URL you are trying to access is wrong.";
echo json_encode($response);
return;
}
if (!checkUserPolicy(@$_SESSION['cdash']['loginid'], $project_array['id'], 1)) {
$response['requirelogin'] = 1;
echo json_encode($response);
return;
}
$response = begin_JSON_response();
$response['title'] = "CDash - {$projectname}";
$response['feed'] = $CDASH_ENABLE_FEED;
$response['showcalendar'] = 1;
$Banner = new Banner();
$Banner->SetProjectId(0);
$text = $Banner->GetText();
$banners = array();
if ($text !== false) {
$banners[] = $text;
}
$Banner->SetProjectId($projectid);
$text = $Banner->GetText();
if ($text !== false) {
$banners[] = $text;
}
$response['banners'] = $banners;
$site_response = array();
// If parentid is set we need to lookup the date for this build
// because it is not specified as a query string parameter.
if (isset($_GET['parentid'])) {
$parentid = pdo_real_escape_numeric($_GET['parentid']);
$parent_build = new Build();
$parent_build->Id = $parentid;
$date = $parent_build->GetDate();
$response['parentid'] = $parentid;
} else {
$response['parentid'] = -1;
}
list($previousdate, $currentstarttime, $nextdate) = get_dates($date, $project_array['nightlytime']);
// Main dashboard section
get_dashboard_JSON($projectname, $date, $response);
$response['displaylabels'] = $project_array['displaylabels'];
$page_id = 'index.php';
$response['childview'] = 0;
if ($CDASH_USE_LOCAL_DIRECTORY && file_exists('local/models/proProject.php')) {
include_once 'local/models/proProject.php';
$pro = new proProject();
$pro->ProjectId = $projectid;
$response['proedition'] = $pro->GetEdition(1);
}
if ($currentstarttime > time() && !isset($_GET['parentid'])) {
$response['error'] = 'CDash cannot predict the future (yet)';
echo json_encode($response);
return;
}
// Menu definition
$response['menu'] = array();
$beginning_timestamp = $currentstarttime;
$end_timestamp = $currentstarttime + 3600 * 24;
$beginning_UTCDate = gmdate(FMT_DATETIME, $beginning_timestamp);
$end_UTCDate = gmdate(FMT_DATETIME, $end_timestamp);
if ($project_instance->GetNumberOfSubProjects($end_UTCDate) > 0) {
$response['menu']['subprojects'] = 1;
}
if (isset($_GET['parentid'])) {
$page_id = 'indexchildren.php';
$response['childview'] = 1;
// When a parentid is specified, we should link to the next build,
// not the next day.
//.........这里部分代码省略.........
示例15: pdo_connect
<?php
include_once "pdo_mysql.php";
$username = "root";
$password = "";
$host = "localhost";
$database = "vaproject";
$server = pdo_connect($host, $username, $password);
$connection = pdo_select_db($database, $server);
$datasets = ["fri", "sat", "sun"];
$datasetsLabels = ["Friday", "Saturday", "Sunday"];
$whichDay = htmlspecialchars($_GET["day"]);
$whichDay = array_search($whichDay, array_values($datasetsLabels));
$inputDay = $datasets[$whichDay];
$whichPlace = htmlspecialchars($_GET["place"]);
$whatTime = (int) htmlspecialchars($_GET["time"]);
$position = htmlspecialchars($_GET["position"]);
$firstquery = pdo_query("select * from places where name = '" . $whichPlace . "'");
$firstresult = pdo_fetch_assoc($firstquery);
$xposition = $firstresult["x"];
$yposition = $firstresult["y"];
$selectedCategory = $firstresult["category"];
if (!strcasecmp($position, "after")) {
$myquery = "Select move.name, count(*) as number, move.category, move.x, move.y from movement_combined move, \n (select id,min(timestamp) as timestamp from movement_combined where id in (select distinct(id) from movement_combined \n where name = '" . $whichPlace . "' and HOUR(timestamp) = " . $whatTime . " and day = '" . $inputDay . "') and day = '" . $inputDay . "' and \n HOUR(timestamp) = " . ($whatTime + 1) . " group by id) as temp where temp.timestamp = move.timestamp and temp.id = move.id \n group by move.name order by number DESC limit 5";
} else {
$myquery = "Select move.name, count(*) as number, move.category, move.x, move.y from movement_combined move, \n (select id,max(timestamp) as timestamp from movement_combined where id in (select distinct(id) from movement_combined \n where name = '" . $whichPlace . "' and HOUR(timestamp) = " . $whatTime . " and day = '" . $inputDay . "') and day = '" . $inputDay . "' and \n HOUR(timestamp) = " . ($whatTime - 1) . " group by id) as temp where temp.timestamp = move.timestamp and temp.id = move.id \n group by move.name order by number DESC limit 5";
}
$query = pdo_query($myquery);
if (!$query) {
echo pdo_error();
die;