本文整理汇总了PHP中DatabaseConnection::get方法的典型用法代码示例。如果您正苦于以下问题:PHP DatabaseConnection::get方法的具体用法?PHP DatabaseConnection::get怎么用?PHP DatabaseConnection::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseConnection
的用法示例。
在下文中一共展示了DatabaseConnection::get方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: select
public function select($query)
{
$link = DatabaseConnection::get();
$result = mysql_query($query, $link);
if (!$result) {
$this->handleDatabaseError($link);
}
$rows = array();
while ($row = mysql_fetch_assoc($result)) {
array_push($rows, $row);
}
DatabaseConnection::closeResult($result);
DatabaseConnection::closeConnection($link);
return $rows;
}
示例2: get
<?php
class DatabaseConnection
{
public static function get()
{
static $db = null;
if ($db == null) {
$db = new DatabaseConnection();
}
return $db;
}
private $_handle = null;
private function __construct()
{
$this->_handle =& mysql_connect('127.0.0.1', 'root', '12345678');
}
public function handle()
{
return $this->_handle;
}
}
print "Handle = " . DatabaseConnection::get()->handle() . "\n";
print "Handle = " . DatabaseConnection::get()->handle() . "\n";
// $db = new DatabaseConnection();
// vim600:ts=4 st=4 foldmethod=marker foldmarker=<<<,>>>
// vim600:syn=php commentstring=//%s
示例3: DatabaseConnection
<?php
require_once "php/DatabaseConnection.php";
$db = new DatabaseConnection();
$result = $db->get("SELECT * FROM games WHERE id=:id", array(":id" => $_POST['gameId']));
if ($result[0]['guests'] == "") {
$guests = "";
} else {
$guests = explode(",", $result[0]['guests']);
foreach ($guests as $key => $guest) {
if ($guest == $_POST['player']) {
unset($guests[$key]);
}
}
$guests = array_values($guests);
if (count($guests) == 0) {
$guestList = "";
} else {
$guestList = $guests[0];
for ($i = 1; $i < count($guests); $i++) {
$guestList .= "," . $guests[$i];
}
}
}
$db->change("UPDATE games SET guests=:guests WHERE id=:id", array(":id" => $_POST['gameId'], ":guests" => $guestList));
示例4: JSON_encode
<?php
session_start();
require_once "php/DatabaseConnection.php";
$db = new DatabaseConnection();
$result = $db->get("SELECT * FROM games");
echo JSON_encode($result);
示例5: escapeStr
public static function escapeStr($value)
{
$link = DatabaseConnection::get();
$value = mysql_escape_string($value);
DatabaseConnection::closeConnection($link);
return $value;
}
示例6: htmlspecialchars
<?php
//process Ajax username request
$username = htmlspecialchars($_REQUEST['username']);
//include db singleton object
require_once 'Singleton.php';
$db = DatabaseConnection::get()->handle();
//$db->debug = true;
//query to check weather username exist
$recordSet =& $db->Execute('select Name from Patterns where Name = "' . $username . '" group by Name');
if ($recordSet->RecordCount() == 1) {
echo 1;
} else {
0;
}
$recordSet->Close();
示例7: get
<?php
class DatabaseConnection
{
public static function get()
{
static $db = null;
if ($db == null) {
$db = new DatabaseConnection();
}
return $db;
}
private $_handle = null;
private function __construct()
{
$dsn = 'mysql:host=localhost;dbname=laravel';
$this->_handle =& new PDO($dsn, 'root', '');
}
public function handle()
{
return $this->_handle;
}
}
var_dump(DatabaseConnection::get()->handle());
var_dump(DatabaseConnection::get()->handle());
示例8: DatabaseConnection
<?php
session_start();
require_once "php/DatabaseConnection.php";
$db = new DatabaseConnection();
$results1 = $db->get("SELECT * FROM games WHERE gameName=:gameName", array(":gameName" => $_POST['gameName']));
$results2 = $db->get("SELECT * FROM games WHERE hostName=:hostName", array(":hostName" => $_POST['hostName']));
if (count($results1) > 0) {
echo "gameName";
//JSON_encode(array("status"=>"gameName"));
} else {
if (count($results2) > 0) {
echo "hostName";
//JSON_encode(array("status"=>"hostName"));
} else {
$db->change("INSERT INTO games (gameName,hostName,gameType,guests) VALUES (:gameName,:hostName,:gameType,'')", array(":hostName" => $_POST['hostName'], ":gameName" => $_POST['gameName'], ":gameType" => $_POST['gameType']));
$_SESSION['hostName'] = $_POST['hostName'];
$result = $db->get("SELECT * FROM games WHERE hostName=:hostName", array(":hostName" => $_POST['hostName']));
$_SESSION['gameId'] = $result[0]['id'];
echo $_SESSION['gameId'];
}
}
示例9: function
* its default settings. However, you will usually configure
* your Slim application now by passing an associative array
* of setting names and values into the application constructor.
*/
$app = new Slim\App();
/**
* Step 3: Define the Slim application routes
*
* Here we define several Slim application routes that respond
* to appropriate HTTP request methods. In this example, the second
* argument for `Slim::get`, `Slim::post`, `Slim::put`, `Slim::patch`, and `Slim::delete`
* is an anonymous function.
*/
$app->get('/', function ($request, $response, $args) {
$response->write("Welcome to Slim!");
$connection = DatabaseConnection::get();
return $response;
});
$app->get('/hello[/{name}]', function ($request, $response, $args) {
$response->write("Hello, " . $args['name']);
return $response;
})->setArgument('name', 'World!');
$app->post('/queryServer', function ($request, $response, $args) {
$response = $response->withAddedHeader('Content-Type', 'application/json');
$response = $response->withStatus(200);
$body = $response->getBody();
$body->write(json_encode(array('salt' => Config_Salts::SaltKey)));
return $response;
});
/**
* Step 4: Run the Slim application
示例10: DatabaseConnection
<?php
session_start();
require_once "php/DatabaseConnection.php";
$db = new DatabaseConnection();
$result = $db->get("SELECT * FROM gamedata WHERE gameId=:gameId", array(":gameId" => $_SESSION['gameId']));
if (count($result) > 0) {
echo $result[count($result) - 1]['gamedata'];
}