当前位置: 首页>>代码示例>>PHP>>正文


PHP create_connection函数代码示例

本文整理汇总了PHP中create_connection函数的典型用法代码示例。如果您正苦于以下问题:PHP create_connection函数的具体用法?PHP create_connection怎么用?PHP create_connection使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了create_connection函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: process_query

/**
 * Processes the query and returns the data.
 * @param $query string The SQL query to process
 * @param null $return_type How to return the result (MYSQLI_ASSOC, MYSQLI_NUM, etc.)
 */
function process_query($query, $connection, $return_type = null)
{
    // if the connection is broken, make a new one
    if (!$connection) {
        unset($connection);
        $connection = create_connection();
    }
    // the name of the database to connect to
    $database_name = Constant::database_name;
    // select the database to process the query in
    mysqli_select_db($connection, $database_name);
    if (is_null($return_type)) {
        // return type is null, so just "run" the query
        return mysqli_query($connection, $query);
    } else {
        // the result when the query is processed
        $result = mysqli_query($connection, $query);
        while ($row = mysqli_fetch_array($result, $return_type)) {
            $row_results[] = $row;
        }
        mysqli_free_result($result);
        // return the row results if it is set (i.e. the while loop was executed),
        // else just return an empty array
        return isset($row_results) ? $row_results : array();
    }
}
开发者ID:joe-el-khoury,项目名称:friendbook-social-network,代码行数:31,代码来源:Conn.php

示例2: UserMailInfo

function UserMailInfo($userid)
{
    if (create_connection($connection)) {
        $userInfo = getUserInfo($connection, $userid);
        //0: id 1: username 2: mail 3: password 4: salt 5: apikey_write 6: apikey_read 7: lastlogin 8: admin 9: gravatar 10: name 11: location 12: timezone 13: language 14: bio
        if ($userInfo != null) {
            echo "Buscando alarmas para usuario: [" . $userInfo[0] . "] " . $userInfo[1] . " - " . $userInfo[10] . "<br>";
            $userActiveAlarms = getUserActiveAlarms($connection, $userid);
            $userRadPowerAlarms = getUserRadPowerAlarms($connection, $userid);
            $userAlarms = array_merge($userActiveAlarms, $userRadPowerAlarms);
            if (count($userAlarms) > 0) {
                echo "Alarmas encontradas, enviando mensaje...<br>";
                $bodyText = formatMailBody($userAlarms);
                $subject = "Alarmas detectadas - ISMSOLAR";
                $mailbody = file_get_contents("/var/www/html/ewatcher-users/MailBody.html");
                $mailbody = str_replace("[BODY]", $bodyText, $mailbody);
                $MailSentOk = sendMail($mailbody, $subject, $userInfo[2], $userInfo[10]);
                if ($MailSentOk) {
                    echo "llamando a markAlarmsAsNotified<br>";
                    markAlarmsAsNotified($connection, $userAlarms);
                }
            } else {
                echo "No se encontraron alarmas activas para notificar.<br>";
            }
        }
    } else {
        echo "Error de conexión a la base de datos...<br>";
    }
}
开发者ID:JSidrach,项目名称:ewatcher-users,代码行数:29,代码来源:alarms.php

示例3: username_is_free

function username_is_free($username)
{
    $connection = create_connection();
    $query = 'SELECT * FROM User WHERE  username =  "' . $username . '";';
    $result = $connection->query($query);
    if ($result->num_rows > 0) {
        return false;
    } else {
        return true;
    }
}
开发者ID:MichaelTzach,项目名称:Coupons-Server,代码行数:11,代码来源:signup_logic.php

示例4: increment_profile_view_counter

 /**
  * Increments the number of times a profile has been viewed in the database.
  * Yay storing user data!
  */
 public function increment_profile_view_counter()
 {
     $viewer_id = $this->viewer_user->user_row["UserID"];
     $viewed_id = $this->viewed_user->user_row["UserID"];
     // God I hate these sql queries
     $sql_query = 'INSERT INTO ' . Constant::profile_views_database_name . ' VALUES ';
     $sql_query .= '(' . $viewer_id . ', ' . $viewed_id . ', 1)';
     $sql_query .= ' ON DUPLICATE KEY UPDATE `ProfileViews` = `ProfileViews` + 1;';
     $connection = create_connection();
     // process the query
     process_query($sql_query, $connection);
     close_connection($connection);
 }
开发者ID:joe-el-khoury,项目名称:friendbook-social-network,代码行数:17,代码来源:Profile.php

示例5: create_linked_user

function create_linked_user($username, $email, $password, $panelType)
{
    // Global variables
    global $redis_enabled, $redis_server;
    // Connect to the DB
    $ret = create_connection($connection);
    if ($ret !== true) {
        return $ret;
    }
    // Connect to Redis
    if ($redis_enabled === true) {
        $redis = new Redis();
        if (!$redis->connect($redis_server)) {
            $redis = false;
        }
    } else {
        $redis = false;
    }
    // Validate input
    $ret = validate_input($username, $email, $password, $panelType);
    if ($ret !== true) {
        end_connection(true, $connection);
        return $ret;
    }
    // Create user
    if (create_user($username, $email, $password, $userid, $apikey, $connection) !== true) {
        end_connection(true, $connection);
        return 'Username already exists';
    }
    // Set the type of user profile
    $prefix = 'data/' . $panelType;
    // Create feeds
    if (create_feeds($prefix . '_feeds.json', $feeds, $apikey) !== true) {
        end_connection(true, $connection);
        return 'Error while creating the feeds';
    }
    // Create inputs
    if (create_inputs($prefix . '_inputs.json', $userid, $inputs, $connection, $redis) !== true) {
        end_connection(true, $connection);
        return 'Error while creating the inputs';
    }
    // Create processes
    if (create_processes($prefix . '_processes.json', $feeds, $inputs, $apikey) !== true) {
        end_connection(true, $connection);
        return 'Error while creating the processes';
    }
    end_connection(false, $connection);
    return true;
}
开发者ID:JSidrach,项目名称:ewatcher-users,代码行数:49,代码来源:query.php

示例6: delete_user

function delete_user($username)
{
    // Connect to the DB
    $ret = create_connection($connection);
    if ($ret !== true) {
        return $ret;
    }
    // Validate input
    $ret = validate_input($username);
    if ($ret !== true) {
        $connection->close();
        return $ret;
    }
    // Get user data
    $user_data = get_user_data($username, $connection);
    if ($user_data === false) {
        $connection->close();
        return 'Username provided does not exist';
    }
    // Delete feeds
    if (delete_feeds($user_data, $connection) !== true) {
        $connection->close();
        return 'Error while deleting the feeds';
    }
    // Delete inputs
    if (delete_inputs($user_data, $connection) !== true) {
        $connection->close();
        return 'Error while deleting the inputs';
    }
    // Delete EWatcher panels
    if (delete_ewatcher($user_data, $connection) !== true) {
        $connection->close();
        return 'Error while deleting user configuration (EWatcher)';
    }
    // Delete user
    if (delete_user_data($user_data, $connection) !== true) {
        $connection->close();
        return 'Error while deleting user data';
    }
    $connection->close();
    return true;
}
开发者ID:JSidrach,项目名称:ewatcher-users,代码行数:42,代码来源:delete_query.php

示例7: session_login

function session_login($username, $password)
{
    $connection = create_connection();
    $query = 'SELECT * FROM User WHERE  username =  "' . $username . '";';
    $result = $connection->query($query);
    if ($result->num_rows > 0) {
        $row = $result->fetch_assoc();
        if ($password == $row['password']) {
            //this is for correct login
            if (!$_SESSION) {
                session_start();
            }
            $_SESSION['username'] = $row['username'];
            determine_role($connection, $username);
            return true;
        } else {
            //this is for incorrect pass
            return false;
        }
    } else {
        //this is for username doesnt exist
        return false;
    }
}
开发者ID:MichaelTzach,项目名称:Coupons-Server,代码行数:24,代码来源:session_manager.php

示例8: mysql_free_result

//釋放記憶體空間
mysql_free_result($result);
mysql_close($link);
?>
    <hr>
    <form name="myForm" method="post" action="post_replyB.php">
      <input type="hidden" name="reply_id" value="<?php 
echo $id;
?>
">
      <table border="0" width="800" align="center" cellspacing="0">
        <tr bgcolor="#0084CA" align="center">
          <td colspan="2"><font color="white">請在此輸入您的回覆</font></td>
        </tr>
        <?php 
$link = create_connection() or die("connecting fails!");
$username = $_SESSION['username'];
$sql = "SELECT name FROM business Where account = '{$username}'";
$result = execute_sql("user", $sql, $link);
mysql_close($link);
?>
        <tr bgcolor="#D9F2FF">
          <td width="15%">使用者</td>
          <td width="85%"><input name="author" type="text" value="<?php 
echo mysql_result($result, 0, 0);
?>
" size="50" readonly></td>
        </tr>
        <tr bgcolor="#D9F2FF">
          <td width="15%">內容</td>
          <td width="85%"><textarea name="content" cols="50" rows="5"></textarea></td>
开发者ID:bob2993714,项目名称:project,代码行数:31,代码来源:show_newsB.php

示例9: header

require_once "dbtools.inc.php";
header("Content-type:text/html;charset=utf-8");
//取得新增的使用者帳號與人數!
$new_account = $_POST["new_account"];
$new_people = $_POST["new_people"];
$new_key = random(8);
function random($length)
{
    $key = '';
    $pattern = "1234567890";
    for ($i = 0; $i < $length; $i++) {
        $key .= $pattern[rand(0, 9)];
    }
    return $key;
}
$link = create_connection();
$sql = "SELECT * FROM nfc Where account='{$new_account}'";
$result = execute_sql("nfc", $sql, $link);
//若帳號已有人用
if (mysql_num_rows($result) != 0) {
    mysql_free_result($result);
    $check = false;
    echo "failed";
    echo "<script type='text/javascript'>";
    echo "alert('您所設定的帳號已有人使用,請更換其他帳號!')";
    echo "history.back()";
    echo "</script>";
} else {
    mysql_free_result($result);
    //執行SQL指令直接新增帳號與人數
    $sql = "INSERT INTO nfc(account,people,keynumber)VALUES('{$new_account}','{$new_people}','{$new_key}')";
开发者ID:crew1274,项目名称:nfc_web,代码行数:31,代码来源:input.php

示例10: get_user_row_by_id

 /**
  * @param $user_id int The id of the user whose user row to retrieve from the database.
  * @return array The array containing the row of the user, if it exists.
  */
 public static function get_user_row_by_id($user_id)
 {
     $sql_query = 'SELECT * FROM `' . Constant::user_database_name . '` ';
     $sql_query .= 'WHERE UserID="' . $user_id . '";';
     $connection = create_connection();
     // the user row with the particular id; it could be empty
     $user_row = process_query($sql_query, $connection, MYSQLI_ASSOC);
     // close the connection before exiting the function
     close_connection($connection);
     // returns an empty array if the user row doesn't exists
     return empty($user_row) ? array() : $user_row;
 }
开发者ID:joe-el-khoury,项目名称:friendbook-social-network,代码行数:16,代码来源:User.php

示例11: reset_database

/**
 * Reset database
 */
function reset_database($con)
{
    // Set number of results to zero
    $query = "UPDATE excerpts SET v1Results = 0, v2Results = 0, v3Results = 0, \n            totalResults = 0";
    my_exec_query($con, $query);
    // Delete all results
    $query = "DELETE FROM results";
    my_exec_query($con, $query);
    // Delete all results
    $query = "DELETE FROM subjects";
    my_exec_query($con, $query);
    // Close DB connection
    mysqli_close($con);
    $con = create_connection();
    // Reset auto increment indeces
    $query = "ALTER TABLE results AUTO_INCREMENT = 0";
    my_exec_query($con, $query);
    $query = "ALTER TABLE subjects AUTO_INCREMENT = 0";
    my_exec_query($con, $query);
    return $con;
}
开发者ID:beckgom,项目名称:msaf,代码行数:24,代码来源:utils.php

示例12: create_connection

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--

Oriol Nieto
oriol -at- nyu -dot- edu
MARL, NYU

-->
<?php 
require 'utils.php';
// Establish DB connection
$con = create_connection();
// Sanitize strings before inserting into dataset
$first_name = sanitize_str($con, $_POST['first_name']);
$last_name = sanitize_str($con, $_POST['last_name']);
$email = sanitize_str($con, $_POST['email']);
$music_training = sanitize_str($con, $_POST['music_training']);
$comments = sanitize_str($con, $_POST['comments']);
// Update Subject
update_subject($con, $first_name, $last_name, $email, $music_training, $comments, $_POST['subjectID']);
// Send email
$email_message = "You have a new result!";
$headers = 'From: ' . $first_name . "\r\n" . 'Reply-To: oriol@nyu.edu' . "\r\n" . 'X-Mailer: PHP/' . phpversion();
@mail("oriol@nyu.edu", "Boundaries Experiment", $email_message, $headers);
// Close DB connection
mysqli_close($con);
?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
开发者ID:beckgom,项目名称:msaf,代码行数:31,代码来源:submit.php

示例13: create_connection

<?php

create_connection('localhost', 1740);
function create_connection($host, $port)
{
    $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
    if (!is_resource($socket)) {
        echo 'Unable to create socket: ' . socket_strerror(socket_last_error()) . PHP_EOL;
    } else {
        echo "Socket created.\n";
    }
    if (!socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1)) {
        echo 'Unable to set option on socket: ' . socket_strerror(socket_last_error()) . PHP_EOL;
    } else {
        echo "Set options on socket.\n";
    }
    if (!socket_bind($socket, $host, $port)) {
        echo 'Unable to bind socket: ' . socket_strerror(socket_last_error()) . PHP_EOL;
    } else {
        echo "Socket bound to port {$port}.\n";
    }
    if (!socket_listen($socket, SOMAXCONN)) {
        echo 'Unable to listen on socket: ' . socket_strerror(socket_last_error());
    } else {
        echo "Listening on the socket.\n";
    }
    while (true) {
        $connection = @socket_accept($socket);
        if ($connection) {
            echo "Client {$connection} connected!\n";
            send_data($connection);
开发者ID:ryanstewart,项目名称:PHP-Socket-Demo,代码行数:31,代码来源:socket_quotes.php

示例14: set_time_limit

<?php

set_time_limit(15);
// Define uma informação para testes, apenas
$config->test = true;
// Cria uma conexão padrão
if (is_localhost()) {
    create_connection('mysqli://root@127.0.0.1/core_project');
}
// Cria uma conexão falsa, para testes
create_connection('mysqli://username:password@servername:1234/dbname' . '?persistent=false&charset=latin1&connect=false', 'fake');
create_connection('mysqli://fakeserver', 'fake2');
create_connection('fakeserver', 'fake3');
// Inclui alguns arquivos que não vão para o commit
if (CORE_DEBUG === true && is_file(dirname(__FILE__) . '/configs.extra.php')) {
    require dirname(__FILE__) . '/configs.extra.php';
}
开发者ID:rentalhost,项目名称:core,代码行数:17,代码来源:configs.php

示例15: client_rate_coupon

function client_rate_coupon($coupon_id, $rating)
{
    $connection = create_connection();
    $coupon = search_coupon_by_id($coupon_id);
    $number_of_ratings = $coupon->number_of_ratings + 1;
    $avg_rating = ($coupon->rating * $coupon->number_of_ratings + $rating) / $number_of_ratings;
    $query = "UPDATE Coupon SET rating = '" . $avg_rating . "', number_of_ratings = '" . $number_of_ratings . "' WHERE coupon_id = '" . $coupon_id . "'";
    $connection->query($query) or trigger_error($connection->error);
}
开发者ID:MichaelTzach,项目名称:Coupons-Server,代码行数:9,代码来源:coupon_logic.php


注:本文中的create_connection函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。