本文整理汇总了PHP中connect函数的典型用法代码示例。如果您正苦于以下问题:PHP connect函数的具体用法?PHP connect怎么用?PHP connect使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了connect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Expire
function Expire()
{
//for link expiration
$delta = 10;
$token2 = $_GET["token"];
$connection = connect();
$tStamp = "select tStamp from accessToken where token='" . $token2 . "'";
$execute = $connection->query($tStamp);
$num = $execute->num_rows;
if ($num) {
$record = $execute->fetch_object();
//echo '<pre>';print_r($record);die;
$timeStam = $record->tStamp;
$timeStam = strtotime($timeStam);
if ($_SERVER['REQUEST_TIME'] - $timeStam > $delta) {
echo "link has expired";
}
//else {
//checkToken();
//setLinkStatus();
//echo "Please login";
//}
} else {
//no record found n database
}
}
示例2: fetchAllorders
function fetchAllorders()
{
$con = connect();
$result = mysqli_query($con, "SELECT * from orders");
disconnect($con);
return $result;
}
示例3: get_published_posts
function get_published_posts()
{
$posts = connect()->prepare("SELECT * FROM posts JOIN users on posts.userid = users.id WHERE visible != 0 ORDER BY postid DESC");
$posts->execute();
$results = $posts->fetchAll();
return $results;
}
示例4: give_key
function give_key($user)
{
// global $numRecords, $dbConnection, $stmt;
$dbConnection = connect();
/*
Dictionary:
This function is returning an array of vkey, user_id, and user type
*/
$sqlCheck = "select vKey, user_ID, user_type from user where username = '{$user}'";
//Run Query
try {
$stmt = $dbConnection->query($sqlCheck);
//Double check there's a value incase something goes wrong before returning key
if ($stmt->rowcount() != 0) {
return $stmt->fetch(PDO::FETCH_ASSOC);
// Debug by checking whats been returned print_r($sql_return); exit();
// return $sql_return;
// return array($sql_return['vKey'],$sql_return['user_ID'], $sql_return['user_type']);
} else {
if ($stmt === false) {
die("Error executing the query: (An error has occured) {$sqlCheck}");
}
}
} catch (PDOException $error) {
//Display error message if applicable
echo "An error occured: " . $error->getMessage();
}
}
示例5: getAll
function getAll()
{
$conn = connect();
$result = $conn->query("SELECT * FROM comments");
$conn->close();
return $result;
}
示例6: init
function init()
{
$link = connect(false);
if (mysqli_select_db($link, "synapp_db")) {
mysqli_close($link);
unset($link);
return INST_DB_EXISTS;
}
$sql = "CREATE DATABASE synapp_db";
if (!mysqli_query($link, $sql)) {
die("mysql CREATE DATABASE error.");
}
$sql = "ALTER DATABASE synapp_db CHARACTER SET utf8 COLLATE utf8_unicode_ci";
if (!mysqli_query($link, $sql)) {
die("mysql ALTER DATABASE synapp_db CHARACTER SET utf8 COLLATE utf8_unicode_ci error.");
}
if (!mysqli_select_db($link, "synapp_db")) {
die("mysqli_select_db() error.");
}
create_all_languages_table($link);
$sql = "CREATE TABLE IF NOT EXISTS users (user VARCHAR(32) UNIQUE KEY,pass VARCHAR(64),recovery VARCHAR(64)," . "firstdate INT,hfirstdate BIT DEFAULT 0,missed_logins INT DEFAULT 0,last_login INT,hlast_login BIT DEFAULT 0,ip INT UNSIGNED,last_update INT," . "interface_language VARCHAR(4),hinterface_language BIT DEFAULT '0',working_group VARCHAR(32),hworking_group BIT DEFAULT 0,input_language VARCHAR(4),hinput_language BIT DEFAULT 0,hprofile BIT DEFAULT 0," . "gender VARCHAR(1) DEFAULT NULL, hgender BIT DEFAULT 0,birthday DATE, hbirthday BIT DEFAULT 0,studies VARCHAR(256), hstudies BIT DEFAULT 0,studies_type VARCHAR(64), hstudies_type BIT DEFAULT 0,studies_level INT, hstudies_level BIT DEFAULT 0, occupation VARCHAR(256),hoccupation BIT DEFAULT 0," . "email VARCHAR(128),hemail BIT DEFAULT 0,email_confirmation_code VARCHAR(64),confirmed_email BIT DEFAULT 0,avatar VARCHAR(128),hstats BIT DEFAULT 0, ditloid_lock_timestamp INT DEFAULT NULL, ditloid_time_left_when_locked INT DEFAULT 0, gotestbefore INT DEFAULT 0," . "gotestafter INT DEFAULT 0, timer_ctestb_start INT DEFAULT 0, timer_ctestb_end INT DEFAULT 0, timer_utestb_start INT DEFAULT 0, timer_utestb_end INT DEFAULT 0, timer_utesta_start INT DEFAULT 0, timer_utesta_end INT DEFAULT 0, timer_ctesta_start INT DEFAULT 0, timer_ctesta_end INT DEFAULT 0, fbid VARCHAR(255) DEFAULT NULL)";
if (!mysqli_query($link, $sql)) {
die('Error: ' . var_export($link->errorInfo(), true));
}
$sql = "CREATE TABLE `interface_languages` (native_name VARCHAR(32), iso6392_code VARCHAR(4) UNIQUE KEY, users INT DEFAULT 0)";
if (mysqli_query($link, $sql)) {
$sql = "INSERT INTO interface_languages VALUES (\"español\", \"spa\", \"0\")";
mysqli_query($link, $sql);
$sql = "INSERT INTO interface_languages VALUES (\"english\", \"eng\", \"0\")";
mysqli_query($link, $sql);
$sql = "INSERT INTO interface_languages VALUES (\"galego\", \"glg\", \"0\")";
mysqli_query($link, $sql);
$sql = "INSERT INTO interface_languages VALUES (\"polski\", \"pol\", \"0\")";
mysqli_query($link, $sql);
}
$sql = "CREATE TABLE `groups` (name VARCHAR(32), users INT DEFAULT 0)";
if (mysqli_query($link, $sql)) {
$sql = "INSERT INTO groups VALUES (\"DEFAULT_GROUP_A\", \"0\")";
mysqli_query($link, $sql);
$sql = "INSERT INTO groups VALUES (\"DEFAULT_GROUP_B\", \"0\")";
mysqli_query($link, $sql);
}
$sql = "CREATE TABLE IF NOT EXISTS `images` (id VARCHAR(69) UNIQUE KEY, name VARCHAR(32), associated_group VARCHAR(32), uploader VARCHAR(32), KEY(associated_group))";
if (!mysqli_query($link, $sql)) {
die('Error: ' . var_export($link->errorInfo(), true));
}
$sql = "CREATE TABLE IF NOT EXISTS `stats` (user VARCHAR(32),lang VARCHAR(4), day DATE,type INT," . "assigned_group VARCHAR(32), upvotes INT DEFAULT 0, downvotes INT DEFAULT 0, neutralvotes INT DEFAULT 0, popupvotes INT DEFAULT 0, popdownvotes INT DEFAULT 0, popneutralvotes INT DEFAULT 0, count INT DEFAULT 0, UNIQUE INDEX `user_lang_day_type_assigned_group` (`user`, `lang`, `day`, `type`, `assigned_group`))";
if (!mysqli_query($link, $sql)) {
die('Error: ' . var_export($link->errorInfo(), true));
}
$sql = "CREATE TABLE IF NOT EXISTS `test_ranks` (user VARCHAR(32), ttype VARCHAR(32),evals INT,orgfullvotes INT, orghalfvotes INT, orgzerovotes INT, cohfullvotes INT, cohhalfvotes INT, cohzerovotes INT, UNIQUE INDEX uti (user,ttype))";
if (!mysqli_query($link, $sql)) {
die('Error: ' . var_export($link->errorInfo(), true));
}
$sql = "CREATE TABLE IF NOT EXISTS `confirmed_emails` (user VARCHAR(32),email VARCHAR(128) UNIQUE KEY, KEY(user))";
if (!mysqli_query($link, $sql)) {
die('Error: ' . var_export($link->errorInfo(), true));
}
return INST_OK;
}
示例7: load_canned_messages
function load_canned_messages($locale, $groupid)
{
global $mysqlprefix;
$link = connect();
$query = "select id, vcvalue from {$mysqlprefix}chatresponses " . "where locale = '" . $locale . "' AND (" . ($groupid ? "groupid = {$groupid}" : "groupid is NULL OR groupid = 0") . ") order by vcvalue";
$result = select_multi_assoc($query, $link);
if (!$groupid && count($result) == 0) {
foreach (explode("\n", getstring_('chat.predefined_answers', $locale)) as $answer) {
$result[] = array('id' => '', 'vcvalue' => $answer);
}
if (count($result) > 0) {
$updatequery = "insert into {$mysqlprefix}chatresponses (vcvalue,locale,groupid) values ";
for ($i = 0; $i < count($result); $i++) {
if ($i > 0) {
$updatequery .= ", ";
}
$updatequery .= "('" . mysql_real_escape_string($result[$i]['vcvalue'], $link) . "','{$locale}', NULL)";
}
perform_query($updatequery, $link);
$result = select_multi_assoc($query, $link);
}
}
mysql_close($link);
return $result;
}
示例8: executeQuery
function executeQuery($query)
{
$pdo = connect();
$ret = $pdo->query($query);
$pdo = close($pdo);
return $ret;
}
示例9: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$dsn = $input->getArgument('dsn');
$db = connect($dsn);
$config = ConfigBuilder::createConfigurationFromConsecutiveFiles($input->getArgument('config'));
$this->dump($config, $db, $output);
}
示例10: scan_connections
function scan_connections()
{
$unix = new unix();
$pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
$pid = $unix->get_pid_from_file($pidfile);
if ($unix->process_exists($pid, basename(__FILE__))) {
$time = $unix->PROCCESS_TIME_MIN($pid);
if ($GLOBALS["OUTPUT"]) {
echo "Artica Task Already running PID {$pid} since {$time}mn\n";
}
return;
}
@file_put_contents($pidfile, getmypid());
if (system_is_overloaded()) {
system_admin_events("Overloaded system, aborting task", __FUNCTION__, __FILE__, __LINE__);
return false;
}
$q = new mysql();
$sql = "SELECT * FROM texttoldap";
$results = $q->QUERY_SQL($sql, "artica_backup");
if (mysql_num_rows($results) == 0) {
return;
}
while ($ligne = mysql_fetch_assoc($results)) {
if (!connect($ligne)) {
continue;
}
import($ligne);
$ID = $ligne["ID"];
}
}
示例11: main
function main()
{
$data = ensure_privileged_api_data_and_token();
$test_group_id = array_get($data, 'group');
if (!$test_group_id) {
exit_with_error('TestGroupNotSpecified');
}
$values = array();
if (array_key_exists('name', $data)) {
$values['name'] = $data['name'];
}
if (array_key_exists('hidden', $data)) {
$values['hidden'] = Database::to_database_boolean($data['hidden']);
}
if (!$values) {
exit_with_error('NothingToUpdate');
}
$db = connect();
$db->begin_transaction();
if (!$db->update_row('analysis_test_groups', 'testgroup', array('id' => $test_group_id), $values)) {
$db->rollback_transaction();
exit_with_error('FailedToUpdateTestGroup', array('id' => $test_group_id, 'values' => $values));
}
if (array_get($data, 'hidden')) {
$db->query_and_get_affected_rows('UPDATE build_requests SET request_status = $1
WHERE request_group = $2 AND request_status = $3', array('canceled', $test_group_id, 'pending'));
}
$db->commit_transaction();
exit_with_success();
}
示例12: block_temporary
function block_temporary($ipUser)
{
$config_file_parsed = $GLOBALS['v'];
include_once 'database.php';
$connection = connect($config_file_parsed["database"]["host"], $config_file_parsed["database"]["user"], $config_file_parsed["database"]["pass"], $config_file_parsed["database"]["database"]);
if ($stmt = mysqli_prepare($connection, "SELECT attempt FROM blocked_ip WHERE ip=?")) {
$k = 0;
$stmt->bind_param("s", $ipUser);
$stmt->execute();
$stmt->bind_result($col1);
echo 'salam: ' . $col1;
while ($stmt->fetch()) {
$k++;
// printf("%i %i", $col1,$k);
}
echo $col1;
$sql = '';
if ($col1 == 0) {
$temp = "'" . $ipUser . "'";
$sql = "INSERT INTO `blocked_ip` VALUES (NULL,{$temp},NOW(),NOW(),1)";
}
if ($col1 == 1) {
$sql = "UPDATE `blocked_ip` SET `start_date`=NOW(),`end_date`=NOW() + INTERVAL 1 HOUR,`attempt`=2 WHERE ip=" . "'" . $ipUser . "'";
}
if ($col1 == 2) {
$sql = "UPDATE `blocked_ip` SET `start_date`=NOW(),`end_date`=NOW() + INTERVAL 1000 HOUR,`attempt`=3 WHERE ip=" . "'" . $ipUser . "'";
}
echo $sql;
if ($col1 >= 0 && $col1 < 3) {
mysqli_query($connection, $sql);
//echo "<h1>afectate:</h1>".mysqli_affected_rows($connection);
}
$stmt->close();
}
}
示例13: addDataTwitter
/**
* Connect the user if he's connected on twitter and if his mail adress is in the DB
* @param $email string contains the user's mail adress
* @param $picture string contains the picture path
*/
function addDataTwitter($email, $picture)
{
$co = connect();
$data = $co->query("SELECT * FROM Student WHERE student_instituteemail = '{$email}' OR student_personalemail = '{$email}'");
$res = $data->fetch();
if (count($res) != 0) {
$accountModel = new AccountModel();
$_SESSION['infoStudent'] = $res;
$_SESSION['infoStudent']['student_avatar'] = $picture;
$id = $res['user_id'];
$idstu = $res['student_id'];
$pourlasess = $co->query("SELECT * FROM User WHERE user_id = {$id}");
$lesdonnees = $pourlasess->fetch();
$_SESSION['infoUser'] = $lesdonnees;
$_SESSION['image'] = $picture;
$trainingResult = $accountModel->getTrainingInformationsForUser('description', $_SESSION['infoUser']['user_id']);
$_SESSION['infoTraining'] = $trainingResult;
//$co->query("UPDATE Student SET `student_avatar` = '$picture' WHERE `student_id` = $idstu");
//print_r($co->errorInfo());
//header('Location: index.php');
echo '<script>document.location.href="index.php"</script>';
} else {
session_unset();
header('Location: index.php?incrip=true');
}
}
示例14: construire_tableau
function construire_tableau($theme = 0, $pertinence = 0, $diff = 0, $nbQuestions)
{
$connexion = connect($host, $port, $user, $password, $database);
//On récupère un recordset correspondant aux critères
$query = "SELECT Q.noq, Q.question, Q.reponse " . "FROM questions Q";
/* ", sujets S, themes T, pertinences P, difficultes D ".
"WHERE Q.noq = S.noq AND S.theme = T.theme AND ".
"S.pertinence = P.pertinence AND S.difficulte = D.difficulte".
"AND S.theme = ". $theme ." AND S.pertinence = ". $pertinence ." AND S.difficulte = ". $diff .";";
*/
$result = exec_query($connexion, $query);
$Nbr = numrows($result);
echo "Nombre d'enregistrements : " . $Nbr . "<BR>";
//Organisation aléatoire des questions
$ints = range(0, $Nbr - 1);
srand(time());
shuffle($ints);
if ($Nbr < $nbQuestions) {
$nbQuestions = $Nbr;
}
// On construit le tableau permettant de trier aléatoirement
for ($i = 0; $i < $nbQuestions && ($row = fetch_array($result, $ints[$i])); $i++) {
echo "libelle Q : " . $row[1] . "<BR>";
$tabQ[$i][0] = $row[0];
// recuperation du numero,
$tabQ[$i][1] = $row[1];
// du libelle,
$tabQ[$i][2] = $row[2];
// de la reponse a la question
}
close($connexion);
return $tabQ;
}
示例15: select
function select($tabela, $coluna, $where, $ordem, $limite)
{
//SQL da consulta
$sql = "SELECT {$coluna} FROM {$tabela} {$where} {$ordem} {$limite}";
//Conectou?
if ($conexao = connect()) {
//conseguiu consultar
if ($query = mysql_query($sql, $conexao)) {
//encountrou alguma coisa?
if (mysql_num_rows($query) > 0) {
$resultados_totais = array();
while ($resultado = mysql_fetch_assoc($query)) {
$resultados_totais[] = $resultado;
}
//fechar conexão
FecharConexao($conexao);
return $resultados_totais;
}
} else {
return false;
}
} else {
return false;
}
}