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


PHP DB_CONNECT::getConnection方法代码示例

本文整理汇总了PHP中DB_CONNECT::getConnection方法的典型用法代码示例。如果您正苦于以下问题:PHP DB_CONNECT::getConnection方法的具体用法?PHP DB_CONNECT::getConnection怎么用?PHP DB_CONNECT::getConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DB_CONNECT的用法示例。


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

示例1: array

/*
 * Following code will create a new product row
 * All product details are read from HTTP Post Request
 */
// array for JSON response
$response = array();
// check for required fields
if (isset($_POST['name']) && isset($_POST['price']) && isset($_POST['description'])) {
    $name = $_POST['name'];
    $price = $_POST['price'];
    $description = $_POST['description'];
    // include db connect class
    require_once __DIR__ . '/db_connect.php';
    // connecting to db
    $db = new DB_CONNECT();
    $con = $db->getConnection();
    // mysql inserting a new row
    $result = mysqli_query($con, "INSERT INTO products(name, price, description) VALUES('{$name}', '{$price}', '{$description}')") or die(mysqli_error($con));
    // check if row inserted or not
    if ($result) {
        // successfully inserted into database
        $response["success"] = 1;
        $response["message"] = "Product successfully created.";
        // echoing JSON response
        echo json_encode($response);
    } else {
        // failed to insert row
        $response["success"] = 0;
        $response["message"] = "Oops! An error occurred.";
        // echoing JSON response
        echo json_encode($response);
开发者ID:TrongkhanhBkhn,项目名称:DaisyIT,代码行数:31,代码来源:create_product.php

示例2: array

<?php

require_once $_SERVER['DOCUMENT_ROOT'] . '/db/db_connect.php';
$db = new DB_CONNECT();
if (isset($_POST["training_id"])) {
    $response = array();
    $training_id = $_POST['training_id'];
    $result = $db->getConnection()->query("SELECT *FROM trainings WHERE training_id = {$training_id}");
    if (!empty($result)) {
        if ($result->num_rows > 0) {
            $result = $result->fetch_array();
            $training = array();
            $training["training_id"] = $result["training_id"];
            $training["name"] = $result["name"];
            $training["owner_login"] = $result["owner_login"];
            $training["time"] = $result["time"];
            $training["dayOfWeek"] = $result["dayOfWeek"];
            $training["agenda"] = $result["agenda"];
            $response["success"] = 1;
            $response["training"] = array();
            array_push($response["training"], $training);
            echo json_encode($response);
        } else {
            $response["success"] = 0;
            $response["message"] = "Training not found";
            echo json_encode($response);
        }
    } else {
        $response["success"] = 0;
        $response["message"] = "Empty result";
        echo json_encode($response);
开发者ID:saegga,项目名称:DeLight-project,代码行数:31,代码来源:get_training.php

示例3: array

<?php

require_once $_SERVER['DOCUMENT_ROOT'] . '/db/db_connect.php';
if (isset($_POST["login"]) && isset($_POST["password"])) {
    $db = new DB_CONNECT();
    $login = $_POST["login"];
    $password = $_POST["password"];
    $response = array();
    $login = $_POST["login"];
    $result = $db->getConnection()->query("SELECT * FROM users WHERE login = '{$login}'");
    if (!empty($result)) {
        if ($result->num_rows > 0) {
            $result = $result->fetch_array();
            $salt = $result["salt"];
            $hash = md5(md5($password . md5(sha1($salt))));
            $iterations = 10;
            for ($i = 0; $i < $iterations; ++$i) {
                $hash = md5(md5(sha1($hash)));
            }
            if ($hash == $result["password"]) {
                $response["success"] = 1;
                $response["user"] = array();
                $response["user"]["first_name"] = $result["first_name"];
                $response["user"]["last_name"] = $result["last_name"];
            } else {
                $response["success"] = 0;
                $response["salt"] = $salt;
                $response["password"] = $hash;
                $response["message"] = "Wrong password";
            }
            echo json_encode($response);
开发者ID:saegga,项目名称:DeLight-project,代码行数:31,代码来源:db_user_check.php

示例4: array

<?php

if (isset($_POST["login"]) && isset($_POST["password"])) {
    require_once $_SERVER['DOCUMENT_ROOT'] . '/db/db_connect.php';
    $db = new DB_CONNECT();
    $response = array();
    $login = $_POST["login"];
    $password = sha1($_POST["password"]);
    $result = $db->getConnection()->query("INSERT INTO users(login, password) VALUES('{$login}', '{$password}')");
    if (!empty($result)) {
        $result = $db->getConnection()->query("SELECT *FROM users WHERE login = '{$login}'");
        if ($result->num_rows > 0) {
            $result = $result->fetch_array();
            if ($password == $result["password"]) {
                $response["success"] = 1;
                $response["message"] = "User successfully added";
            }
            echo json_encode($response);
        } else {
            $response["success"] = 0;
            $response["message"] = "User not created";
            echo json_encode($response);
        }
    } else {
        $response["success"] = 0;
        $response["message"] = "Empty result";
        echo json_encode($response);
    }
} else {
    $response["success"] = 0;
    $response["message"] = "Required field(s) is missing";
开发者ID:saegga,项目名称:DeLight-project,代码行数:31,代码来源:create_user.php

示例5: array

<?php

require_once $_SERVER['DOCUMENT_ROOT'] . '/db/db_connect.php';
$db = new DB_CONNECT();
$response = array();
$result = $db->getConnection()->query("select training_id, name, owner_login, concat_ws(' - ', start_time, end_time) as time, dayOfWeek, agenda, place from trainings");
if (!empty($result)) {
    if ($result->num_rows > 0) {
        while ($raw = mysqli_fetch_object($result)) {
            $training[] = $raw;
        }
        $response['training'] = array();
        array_push($response['training'], $training);
    }
} else {
    $response["success"] = 0;
    $response["message"] = "error mysql query";
}
$result = $db->getConnection()->query("SELECT *FROM `show`");
if (!empty($result)) {
    if ($result->num_rows > 0) {
        $show = array();
        while ($raw = mysqli_fetch_object($result)) {
            $show[] = $raw;
        }
        $response['show'] = array();
        array_push($response['show'], $show);
    }
} else {
    $response["success"] = 0;
    $response["message"] = "error mysql query";
开发者ID:saegga,项目名称:DeLight-project,代码行数:31,代码来源:get_all_events.php

示例6: array

<?php

require_once $_SERVER['DOCUMENT_ROOT'] . '/db/db_connect.php';
$db = new DB_CONNECT();
if (isset($_POST["key_value"])) {
    $response = array();
    $key = $_POST["key_value"];
    $result = $db->getConnection()->query("SELECT *FROM register_key WHERE key_value = sha1({$key})");
    if (!empty($result)) {
        if ($result->num_rows > 0) {
            $result = $result->fetch_array();
            $response["success"] = 1;
            $response["key_status"] = $result["free"];
            echo json_encode($response);
        } else {
            $response["success"] = 0;
            $response["message"] = "Key not found";
            echo json_encode($response);
        }
    } else {
        $response["success"] = 0;
        $response["message"] = "Empty result";
        echo json_encode($response);
    }
} else {
    $response["success"] = 0;
    $response["message"] = "Required field(s) is missing";
    echo json_encode($response);
}
开发者ID:saegga,项目名称:DeLight-project,代码行数:29,代码来源:db_key_check.php

示例7:

<?php

require_once $_SERVER['DOCUMENT_ROOT'] . '/db/db_connect.php';
//$user_id = $_SESSION["user_id"];
//if ($user_id){
$query = "select login from users where login = '{$user_id}'";
$db = new DB_CONNECT();
$result = $db->getConnection()->query($query);
$result = $result->fetch_array();
if ($user_id == $result["login"]) {
    $query = "select * from trainings";
    $result = $db->getConnection()->query($query);
    for ($i = 0; $i < $result->num_rows; $i++) {
        $row = $result->fetch_array();
        echo '<div class="schedule-row"><div class="vert-divider"></div>' . '<span class="dayofweek">' . $row["dayOfWeek"] . ' ' . $row["start_time"] . ' - ' . $row["end_time"] . '</span>' . '</div>' . "\n";
    }
}
//} else {
//echo '<p class="autorization-error">Для доступа к данной странице, необходимо авторизироваться.</p>';
//}
开发者ID:saegga,项目名称:DeLight-project,代码行数:20,代码来源:events.php

示例8: json_encode

<?php

require_once $_SERVER['DOCUMENT_ROOT'] . '/db/db_connect.php';
$db = new DB_CONNECT();
$response = array();
$result = $db->getConnection()->query("SELECT *FROM trainings");
if (!empty($result)) {
    if ($result->num_rows > 0) {
        $training = array();
        while ($raw = mysqli_fetch_object($result)) {
            $training[] = $raw;
        }
        $response["training"] = array();
        array_push($response["training"], $training);
    } else {
        $response["success"] = 1;
        $response["message"] = "Empty result";
    }
} else {
    $response["success"] = 0;
    $response["message"] = "mysql error";
}
echo json_encode($response);
开发者ID:saegga,项目名称:DeLight-project,代码行数:23,代码来源:get_all_trainings.php


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