本文整理汇总了PHP中DB_CONNECT类的典型用法代码示例。如果您正苦于以下问题:PHP DB_CONNECT类的具体用法?PHP DB_CONNECT怎么用?PHP DB_CONNECT使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DB_CONNECT类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create_table
public static function create_table($name)
{
$query_string = "CREATE TABLE IF NOT EXISTS " . $name . "_questions" . "(\n\t\t\t\t\t\t\t `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t\t\t `question` text NOT NULL,\n\t\t\t\t\t\t\t `option1` text NOT NULL,\n\t\t\t\t\t\t\t `option2` text NOT NULL,\n\t\t\t\t\t\t\t `option3` text NOT NULL,\n\t\t\t\t\t\t\t `option4` text NOT NULL,\n\t\t\t\t\t\t\t `correct_ans` text NOT NULL,\n\t\t\t\t\t\t\t `marks` int(11) NOT NULL,\n\t\t\t\t\t\t\t `negative_marks` int(11) NOT NULL,\n\t\t\t\t\t\t\t PRIMARY KEY (`id`)\n\t\t\t\t\t\t\t)";
$db = new DB_CONNECT();
$result = $db->query_database($query_string);
return $result;
}
示例2: create_table
public static function create_table($name)
{
$query_string = "CREATE TABLE IF NOT EXISTS " . $name . "_users " . "(\n\t\t\t\t\t\t\t `first_name` varchar(30) NOT NULL,\n\t\t\t\t\t\t\t `last_name` varchar(30) NOT NULL,\n\t\t\t\t\t\t\t `email` varchar(30) NOT NULL,\n\t\t\t\t\t\t\t `phone_number` varchar(13) NOT NULL,\n\t\t\t\t\t\t\t `score` int(11) NOT NULL DEFAULT '0',\n\t\t\t\t\t\t\t `questions_attempted` int(11) NOT NULL DEFAULT '0',\n\t\t\t\t\t\t\t `correct_ans` int(11) NOT NULL DEFAULT '0',\n\t\t\t\t\t\t\t `wrong_ans` int(11) NOT NULL DEFAULT '0',\n\t\t\t\t\t\t\t PRIMARY KEY (`email`),\n\t\t\t\t\t\t\t UNIQUE KEY `phone_number` (`phone_number`)\n\t\t\t\t\t\t\t)";
$db = new DB_CONNECT();
$result = $db->query_database($query_string);
return $result;
}
示例3: __construct
public function __construct()
{
$DB_CONNECT = new DB_CONNECT();
$this->connection = new \mysqli($DB_CONNECT->getHost(), $DB_CONNECT->getUsername(), $DB_CONNECT->getPassword(), $DB_CONNECT->getName());
if ($this->connection->connect_errno) {
echo "Failed to connect to MySQLI: " . $this->connection->connect_error;
}
}
示例4: __construct
public function __construct()
{
try {
$DB_CONNECT = new DB_CONNECT();
$this->databaseConnection = mysql_connect($DB_CONNECT->getHost(), $DB_CONNECT->getUsername(), $DB_CONNECT->getPassword()) or die("Unable to connect to MySQL");
$this->selectedDatabase = mysql_select_db($DB_CONNECT->getDatabase(), $this->databaseConnection) or die("Could not select database");
} catch (Exception $error) {
echo 'Caught exception: ', $error->getMessage(), "\n";
}
}
示例5: getProductes
function getProductes($id)
{
//Ens connectem a la base de dades
require_once '../db_connect.php';
/*Creem la connexió*/
$db = new DB_CONNECT();
$con = $db->connect();
$productes = array();
$sql = "SELECT * FROM nfc_producte WHERE Id_categoria='{$id}'";
$query = mysqli_query($con, $sql);
while ($producte = mysqli_fetch_assoc($query)) {
$productes[] = $producte;
}
return json_encode($productes);
$db->close($con);
}
示例6: getAllCategories
function getAllCategories()
{
//Ens connectem a la base de dades
require_once 'db_connect.php';
/*Creem la connexió*/
$db = new DB_CONNECT();
$con = $db->connect();
$categories = array();
$sql = "SELECT * FROM nfc_categoria ORDER BY id_categoria";
$query = mysqli_query($con, $sql);
while ($categoria = mysqli_fetch_assoc($query)) {
$categories[] = $categoria;
}
return json_encode($categories);
$db->close($con);
}
示例7: DB_CONNECT
<?php
//make database connection
require_once __DIR__ . '/db_connect.php';
$db = new DB_CONNECT();
$conn = $db->connect();
//initializing response array
$response = array();
//default city value for testing web without android post
$cityRetrived = "toronto";
//get post data city
if (isset($_GET["city"])) {
$cityRetrived = $_GET['city'];
require_once __DIR__ . '/APICalls.php';
//sql query for current conditions
$result2 = $conn->query("SELECT * FROM `currentConditions` WHERE city = '{$cityRetrived}'");
//check for empty data
if (!empty($result2)) {
if ($result2->num_rows > 0) {
//getting row array from database
$result2 = mysqli_fetch_array($result2);
//storing row into data arrary
$data = array();
$data["city"] = $result2["city"];
$data["temp"] = $result2["temp"];
$data["apparantTemp"] = $result2["apparantTemp"];
$data["summary"] = $result2["summary"];
$data["icon"] = $result2["icon"];
$data["time"] = $result2["time"];
$data["pressure"] = $result2["pressure"];
$data["dewPoint"] = $result2["dewPoint"];
示例8: array
{
"phonenumber":"8950683510";
},
{
"phonenumber":"8950683512";
},
{
"phonenumber":"8950683543";
}
]
}
*/
require_once "includes/db_connect.php";
require_once "includes/functions.php";
$response = array();
$db = new DB_CONNECT();
// To count how many number are added in the table family
$count = 0;
if (isset($_POST["contacts"]) && isset($_POST["id"])) {
// fecthing the json string encoded from the url and decoding it into the json array
//$json = json_decode($_POST["contacts"],true);
$phonearrays = decode_JSON($_POST["contacts"]);
$id = $_POST["id"];
$number = array();
$response["phonenumbers"] = array();
foreach ($phonearrays as $number) {
// convert the number
$original_number = $number["phonenumber"];
if ($original_number[0] == '0') {
$number = substr($original_number, 1);
$original_number = "+91" . $number;
示例9: DB_CONNECT
<?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);
示例10: getTaulaProductsCarrito
function getTaulaProductsCarrito()
{
session_start();
$productes_afegits = array();
$carrito = "<table id=\"taula_carrito\">";
$array_productes = explode(",", $_SESSION['carro']);
$carrito .= "<tr>";
$carrito .= "<td id=\"fila_carrito\">";
$carrito .= "<p class=\"element_taula header_taula\">IMATGE</p>";
$carrito .= "</td>";
$carrito .= "<td id=\"fila_carrito\">";
$carrito .= "<p class=\"element_taula header_taula\">NOM</p>";
$carrito .= "</td>";
$carrito .= "<td id=\"fila_carrito\">";
$carrito .= "<p class=\"element_taula header_taula\">PREU (c/u)</p>";
$carrito .= "</td>";
$carrito .= "<td id=\"fila_carrito\">";
$carrito .= "<p class=\"element_taula header_taula\">PREU TOTAL</p>";
$carrito .= "</td>";
$carrito .= "<td id=\"fila_carrito\">";
$carrito .= "<p class=\"element_taula header_taula\">MODIFICAR</p>";
$carrito .= "</td>";
$quantitat_productes = 0;
$preu_total = 0;
foreach ($array_productes as $producte) {
if ($producte != "") {
$id_producte = substr($producte, 0, strpos($producte, "/"));
$id_producte = trim($id_producte, "[");
if (!in_array($id_producte, $productes_afegits)) {
//Ens connectem a la base de dades
require_once '../db_connect.php';
/*Creem la connexió*/
$db = new DB_CONNECT();
$con = $db->connect();
$sql = "SELECT * FROM nfc_producte WHERE id_producte = " . $id_producte . ";";
$query = mysqli_query($con, $sql) or die(mysqli_error($con));
$row = mysqli_fetch_array($query);
$carrito .= "<tr>";
$carrito .= "<td id=\"fila_carrito\">";
$carrito .= "<img class=\"element_taula\" width=\"100\" height=\"100\" src=\"../" . $row["URL_imatge"] . "\" onclick=\"removeFromCart(" . $id_producte . ")\"/>";
$carrito .= "</td>";
$carrito .= "<td id=\"fila_carrito\">";
$nom_producte = substr($producte, strpos($producte, "/") + 1, strpos($producte, "]"));
$nom_producte = trim($nom_producte, "]");
$carrito .= "<p class=\"element_taula\">" . $nom_producte . " (x" . count(preg_grep($producte, $array_productes)) . ")</p>";
$productes_afegits[] = $id_producte;
$carrito .= "</td>";
$quantitat_productes += count(preg_grep($producte, $array_productes));
$carrito .= "<td id=\"fila_carrito\">";
$carrito .= "<p class=\"element_taula\">" . $row["Preu_IVA"] . "</p>";
$carrito .= "</td>";
$carrito .= "<td id=\"fila_carrito\">";
$carrito .= "<p class=\"element_taula\">" . $row["Preu_IVA"] * count(preg_grep($producte, $array_productes)) . "</p>";
$carrito .= "</td>";
$preu_total += $row["Preu_IVA"] * count(preg_grep($producte, $array_productes));
$carrito .= "<td id=\"fila_carrito\">";
$carrito .= "<img class=\"element_taula\" src=\"../resources/img/delete-product.png\" onclick=\"borrar(" . $id_producte . ");\"/>";
$carrito .= "</td>";
$carrito .= "</tr>";
}
}
}
$carrito .= "<tr>";
$carrito .= "<td id=\"fila_carrito\">";
$carrito .= "<p class=\"element_taula header_taula\">TOTAL</p>";
$carrito .= "</td>";
$carrito .= "<td id=\"fila_carrito\">";
$carrito .= "<p class=\"element_taula\">" . $quantitat_productes . " unitats</p>";
$carrito .= "</td>";
$carrito .= "<td>";
$carrito .= "</td>";
$carrito .= "<td id=\"fila_carrito\">";
$carrito .= "<p class=\"element_taula\">" . $preu_total . " euros</p>";
$carrito .= "</td>";
$carrito .= "<td id=\"fila_carrito\">";
$carrito .= "<button class=\"element_taula\">CONFIRMAR</button>";
$carrito .= "</td>";
$carrito .= "</table>";
return $carrito;
}
示例11: confirm_logged_in
<?php
require_once "/includes/session.php";
require_once "/includes/db_connect.php";
require_once "/includes/functions.php";
confirm_logged_in();
$db = new DB_CONNECT();
if (isset($_POST["calamity"]) && isset($_POST["before_cal"]) && isset($_POST["after_cal"]) && isset($_POST["during_cal"])) {
$calamity = trim($db->mysql_prep($_POST["calamity"]));
$before_cal = trim($db->mysql_prep($_POST["before_cal"]));
$after_cal = trim($db->mysql_prep($_POST["after_cal"]));
$during_cal = trim($db->mysql_prep($_POST["during_cal"]));
if (strlen($calamity) != 0 && strlen($before_cal) && strlen($after_cal) && strlen($during_cal)) {
$queryString = "INSERT INTO guidelines ( calamity , during_cal, after_cal , before_cal ) VALUES( '{$calamity}','{$during_cal}','{$after_cal}' ,'{$before_cal}') ";
echo $queryString;
$result = $db->query_db($queryString);
if ($result) {
//$_POST["message"] = "Inserted to the database";
redirect_to("guidelines.php?message=Inserted to the database");
} else {
echo "Cannot be inserted";
}
} else {
redirect_to("guidelines.php?message=Cannot be inserted. Some Values are Missing");
}
} else {
echo "Problem in the post request";
}
示例12: 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
示例13: array
<?php
/*
* Following code will list all the items
*/
// array for JSON response
$response = array();
// include db connect class
require_once __DIR__ . '/php_includes/DB_CONNECT.php';
// connecting to db
$db = new DB_CONNECT();
// get all items from item table
$result = mysqli_query($db->connect(), "SELECT *FROM item ORDER BY RAND()") or die(mysql_error());
// check for empty result
if (mysqli_num_rows($result) > 0) {
// looping through all results
// item node
$response["items"] = array();
while ($row = mysqli_fetch_array($result)) {
// temp user array
$item = array();
$item["idItem"] = $row["idItem"];
$item["sub_category"] = $row["sub_category"];
$item["category"] = $row["category"];
$item["shop"] = $row["shop"];
$item["user"] = $row["user"];
$item["item_name"] = $row["item_name"];
$item["price"] = $row["price"];
$item["item_image"] = $row["item_image"];
// push single product into final response array
array_push($response["items"], $item);
示例14: DB_CONNECT
<?php
require_once __DIR__ . '/db_connect.php';
$db = new DB_CONNECT();
$output['deals'] = array();
$db->connect();
$q = mysql_query("SELECT * from deals");
while ($row = mysql_fetch_array($q)) {
$temp = array();
$temp['id'] = $row['id'];
$temp['name'] = $row['name'];
$temp['desc'] = $row['description'];
$temp['expire_time'] = $row['expire_time'];
$temp['brand_id'] = $row['brand_id'];
$temp['img'] = $row['image'];
array_push($output['deals'], $temp);
}
header('Content-Type: application/json');
print json_encode($output);
mysql_close();
示例15: array
$response = array();
/*test data
* $username = 'otim';
* $email = 'otim@gmail.com';
* $password = '12345';
*/
// check for required fields
if (isset($_POST["username"]) && isset($_POST["email"]) && isset($_POST["password"]) && (!empty($_POST["username"]) && !empty($_POST["email"]) && !empty($_POST["password"]))) {
$username = $_POST["username"];
$email = $_POST["email"];
$password = $_POST["password"];
$date = date("Y-d-m");
// include db connect class
require_once __DIR__ . '/php_includes/DB_CONNECT.php';
// connecting to db
$db = new DB_CONNECT();
$connection = $db->connect();
// mysql inserting a new row
$result = mysqli_query($connection, "INSERT INTO user(username, email, password,date_joined) VALUES('{$username}', '{$email}', '{$password}','{$date}')");
$userId = mysqli_insert_id($connection);
// check if row inserted or not
if ($result) {
// successfully inserted into database
$response["userId"] = $userId;
$response["success"] = 1;
$response["message"] = "user registered successfully.";
// echoing JSON response
echo json_encode($response);
} else {
// failed to insert row
$response["success"] = 0;