本文整理汇总了PHP中database::prepare方法的典型用法代码示例。如果您正苦于以下问题:PHP database::prepare方法的具体用法?PHP database::prepare怎么用?PHP database::prepare使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类database
的用法示例。
在下文中一共展示了database::prepare方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isMaintenanceNeeded
private function isMaintenanceNeeded()
{
global $config;
global $db;
// TODO: remove this loading after legacy maintenance code has been deleted
if (!isset($db)) {
require_once dirname(dirname(dirname(__FILE__))) . '/classes/config.php';
$config = new config();
require_once dirname(dirname(dirname(__FILE__))) . '/classes/db.php';
$db = new database();
}
$this->lockTable('misc_data');
$today = date('Y-m-d');
$last_maintenance = '0000-00-0000';
// check last time where maintenance was performed
$query = $db->SQL('SELECT `last_maintenance` FROM `misc_data` LIMIT 1');
$lastMaintenanceSaved = false;
while ($row = $db->fetchRow($query)) {
$lastMaintenanceSaved = true;
if (isset($row['last_maintenance'])) {
$last_maintenance = $row['last_maintenance'];
}
}
$db->free($query);
// save new maintenance timestamp
if ($lastMaintenanceSaved) {
$query = $db->prepare('UPDATE `misc_data` SET `last_maintenance`=?');
$db->execute($query, $today);
$db->free($query);
} else {
$query = $db->prepare('INSERT INTO `misc_data` (`last_maintenance`) VALUES (?)');
$db->execute($query, $today);
$db->free($query);
}
$this->unlockTables();
// daily maintenance
return strcasecmp($today, $last_maintenance) !== 0;
}
示例2: getUserIdFromUsername
function getUserIdFromUsername($username)
{
$db = new database();
$db->pick_db("workoutlog");
if ($stmt = $db->prepare("SELECT UserId FROM tbl_workoutlog_users WHERE UserName = ?")) {
$stmt->bind_param('s', $username);
$stmt->execute();
$stmt->bind_result($userId);
$stmt->fetch();
$result = $userId;
}
$db->disconnect();
return isset($result) ? $result : null;
}
示例3: getLastExamDateForAllContacts
function getLastExamDateForAllContacts($UserEmail)
{
//Returns an array of email -> last date
//First is the user, then all contacts
$db = new database();
$db->pick_db("codersvscancer");
if ($stmt = $db->prepare("SELECT ContactEmail FROM tbl_contacts WHERE UserEmail = ?")) {
$stmt->bind_param('s', $UserEmail);
$stmt->execute();
$stmt->bind_result($row);
$contacts = array();
while ($stmt->fetch()) {
array_push($contacts, $row);
}
}
$result[$UserEmail] = getLastExamDateForSingleUser($UserEmail, $db);
foreach ($contacts as $contact) {
$result[$contact] = getLastExamDateForSingleUser($contact, $db);
}
$db->disconnect();
return json_encode($result, JSON_PRETTY_PRINT);
}
示例4: isset
<?php
include "Includes/databaseClassMySQLi.php";
if (isset($_POST["email"]) && isset($_POST["password"])) {
$db = new database();
$db->pick_db("codersvscancer");
$stmt = $db->prepare("SELECT Password FROM tbl_users WHERE UserEmail = ?");
$stmt->bind_param('s', $_POST["email"]);
$stmt->execute();
$stmt->bind_result($passHash);
$stmt->fetch();
if (password_verify($_POST["password"], $passHash)) {
//User/Pass combo valid
session_start();
$_SESSION["UserEmail"] = $_POST["email"];
$result = true;
}
}
echo isset($result) ? $result : false;
示例5: database
<?php
include "Includes/databaseClassMySQLi.php";
if (isset($_POST["username"]) && isset($_POST["password"])) {
$encryptedPass = password_hash($_POST["password"], PASSWORD_DEFAULT);
$db = new database();
$db->pick_db("workoutlog");
if ($stmt = $db->prepare("INSERT INTO tbl_workoutlog_users (UserName, Password) VALUES (?,?)")) {
$stmt->bind_param('ss', $_POST["username"], $encryptedPass);
$stmt->execute();
if ($stmt->affected_rows == 1) {
//Account successfully created, now log the person in
session_start();
$_SESSION["username"] = $_POST["username"];
echo true;
}
}
}
示例6: isset
<?php
include "Includes/databaseClassMySQLi.php";
if (isset($_POST["username"]) && isset($_POST["password"])) {
$db = new database();
$db->pick_db("workoutlog");
$query = "SELECT Password FROM tbl_workoutlog_users WHERE UserName = '" . $_POST["username"] . "'";
$res = $db->send_sql($query);
$stmt = $db->prepare("SELECT Password FROM tbl_workoutlog_users WHERE UserName = ?");
$stmt->bind_param('s', $_POST["username"]);
$stmt->execute();
$stmt->bind_result($passHash);
$stmt->fetch();
if (password_verify($_POST["password"], $passHash)) {
//User/Pass combo valid
session_start();
$_SESSION["username"] = $_POST["username"];
$result = true;
}
}
echo isset($result) ? $result : false;
示例7: database
<?php
include "Includes/databaseClassMySQLi.php";
if (isset($_POST["displayName"]) && isset($_POST["email"]) && isset($_POST["password"])) {
$encryptedPass = password_hash($_POST["password"], PASSWORD_DEFAULT);
$db = new database();
$db->pick_db("codersvscancer");
if ($stmt = $db->prepare("INSERT INTO tbl_users (DisplayName, UserEmail, Password) VALUES (?,?,?)")) {
$stmt->bind_param('sss', $_POST["displayName"], $_POST["email"], $encryptedPass);
$stmt->execute();
if ($stmt->affected_rows == 1) {
//Account successfully created, now log the person in
session_start();
$_SESSION["UserEmail"] = $_POST["email"];
echo true;
}
}
}
示例8: database
<?php
include "Includes/databaseClassMySQLi.php";
session_start();
if (isset($_POST["email"]) && isset($_SESSION["UserEmail"])) {
$db = new database();
$db->pick_db("codersvscancer");
if ($stmt = $db->prepare("INSERT INTO tbl_contacts (ContactEmail, UserEmail) VALUES (?,?)")) {
$stmt->bind_param('ss', $_POST["email"], $_SESSION["UserEmail"]);
$stmt->execute();
if ($stmt->affected_rows == 1) {
//Contact successfully created
echo true;
}
}
}
示例9: database
<?php
session_start();
include "Includes/databaseClassMySQLi.php";
include "Includes/commonFuncs.php";
if (isset($_POST["exercises"]) && isset($_POST["date"]) && isset($_SESSION["username"])) {
$exercises = $_POST["exercises"];
$date = $_POST["date"];
$username = $_SESSION["username"];
$db = new database();
$db->pick_db("workoutlog");
$userId = getUserIdFromUsername($username);
if ($userId != null) {
//Add workout to tbl_workoutlog_workout, get workoutId
$stmt = $db->prepare("INSERT INTO tbl_workoutlog_workout (UserId, WorkoutDate) VALUES (?, STR_TO_DATE(?, '%Y-%m-%d'))");
$stmt->bind_param('is', $userId, $date);
$stmt->execute();
if ($stmt->affected_rows == 1) {
$stmt->free_result();
$res = $db->send_sql("SELECT LAST_INSERT_ID() AS Id");
if ($res->num_rows > 0) {
$row = $res->fetch_assoc();
$workoutId = $row['Id'];
foreach ($exercises as $exercise) {
//Add each exercise to tbl_WorkoutLog_Exercise linking to the workoutId
$stmt = $db->prepare("SELECT ExerciseNameId FROM tbl_workoutlog_exercisename WHERE ExerciseName = ?");
$stmt->bind_param('s', $exercise['name']);
$stmt->execute();
$stmt->bind_result($exerciseNameId);
$stmt->fetch();
$stmt->free_result();
示例10: deleteEntry
/**
* Delete entry.
*
*This function place the url into a delete query.
*
* @param database $db
* @param string $url
* @return mixed
*/
function deleteEntry($db, $url)
{
$sql = "DELETE FROM entries WHERE url=? LIMIT 1";
$stmt = $db->prepare($sql);
return $stmt->execute(array($url));
}