本文整理汇总了PHP中Connection::connection方法的典型用法代码示例。如果您正苦于以下问题:PHP Connection::connection方法的具体用法?PHP Connection::connection怎么用?PHP Connection::connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Connection
的用法示例。
在下文中一共展示了Connection::connection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: connect
public function connect()
{
if (!self::$connection) {
self::$connection = mysql_connect($this->server, $this->username, $this->password);
}
mysql_select_db($this->db);
}
示例2: getInstance
public static function getInstance()
{
//get an instance of the connection
if (Connection::$connection === NULL) {
//if the connection is null
// connect to the database local using the credentials
$host = "localhost";
$database = "CA1-TourBusMassacre";
$username = "rorypb";
$password = "root";
// connection for college database
// $host = "daneel";
// $database = "N00143233playground";
// $username = "N00143233";
// $password = "N00143233";
$dsn = "mysql:host=" . $host . ";dbname=" . $database;
//url for connection
Connection::$connection = new PDO($dsn, $username, $password);
//Connection is made with the variables above
if (!Connection::$connection) {
//if there is no connection
die("Could not connect to database");
//die
}
}
return Connection::$connection;
//return the connection from the credentials above
}
示例3: getInstance
public static function getInstance()
{
if (empty(self::$connection)) {
self::$connection = new self();
return self::$connection;
}
}
示例4: get
public static function get()
{
if (self::$connection == false) {
self::$connection = new PDO('mysql:host=' . self::$host . ';dbname=' . self::$dbname, self::$user, self::$pwd, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'', PDO::ATTR_CASE => 'SET lc_time_names = \'fr_FR\''));
return self::$connection;
} else {
return self::$connection;
}
}
示例5: open_connection
protected static function open_connection()
{
//initialize connection
self::$connection = new mysqli(self::$server, self::$user, self::$password, self::$database);
//error in connection
if (self::$connection->connect_errno) {
echo 'Cannot connect to MySQL server : ' . self::$connection->connect_error;
die;
}
}
示例6: connect
public function connect()
{
if (!isset(self::$connection)) {
//Filen .ini innehåller databasuppkopplingsinfo som databasnamn, lösenord m.m.
$config = parse_ini_file('./config.ini');
//denna fil läggs utanför den mappar användare kan nå för att skydda databasinfo
self::$connection = new mysqli('localhost', $config['username'], $config['password'], $config['dbname']);
}
return self::$connection;
}
示例7: create
public static function create($host, $dbname, $user, $pass)
{
if (self::$connection == null) {
try {
self::$connection = new PDO("mysql:host={$host};dbname={$dbname}", $user, $pass);
} catch (PDOException $e) {
}
}
return self::$connection;
}
示例8: connect
/**
* Connect to the database
*
* @return bool false on failure / mysqli MySQLi object instance on success
*/
public function connect()
{
if (!isset(self::$connection)) {
$config = parse_ini_file(__DIR__ . '/../resources/dbconfig.ini');
self::$connection = new mysqli($config['host'], $config['username'], $config['password'], $config['dbname']);
}
if (self::$connection === false) {
return false;
}
return self::$connection;
}
示例9: get
/**
* Get the connection to the database
*/
public static function get()
{
if (self::$connection == false) {
try {
self::$connection = new PDO('mysql:host=' . self::$host . ';dbname=' . self::$dbname, self::$user, self::$pwd, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'', PDO::ATTR_CASE => 'SET lc_time_names = \'de_DE\'', PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION));
return self::$connection;
} catch (Exception $e) {
echo "erreur de connexion : " . $e->getMessage();
}
} else {
return self::$connection;
}
}
示例10: get
public function get()
{
$sql = $this->_select;
try {
$db = parent::connection();
$stmt = $db->query($sql);
$result = $stmt->fetchAll(PDO::FETCH_OBJ);
$db = null;
echo json_encode($result);
} catch (PDOException $e) {
echo '{"error":{"text":' . $e->getMessage() . '}}';
}
}
示例11: getUser
public function getUser($id)
{
$sql = $this->_select . " WHERE id = :id";
try {
$db = parent::connection();
$stmt = $db->prepare($sql);
$stmt->bindParam("id", $id);
$stmt->execute();
$result = $stmt->fetchObject();
$db = null;
echo json_encode($result);
} catch (PDOException $e) {
echo '{"error":{"text":' . $e->getMessage() . '}}';
}
}
示例12: getInstance
public static function getInstance()
{
if (Connection::$connection === NULL) {
// connect to the database
$host = "localhost";
$database = "photo_gallery";
$username = "root";
$password = "";
$dsn = "mysql:host=" . $host . ";dbname=" . $database;
Connection::$connection = new PDO($dsn, $username, $password);
if (!Connection::$connection) {
die("Could not connect to database");
}
}
return Connection::$connection;
}
示例13: get
public function get()
{
$sql = $this->_select . " LIMIT 1";
try {
$db = parent::connection();
$stmt = $db->prepare($sql);
$stmt->execute();
$result = $stmt->fetchObject();
$db = null;
$result->info = preg_replace("'\r?\n'", '', $result->info);
$result->info = stripslashes($result->info);
$result->info = stripcslashes($result->info);
echo json_encode($result);
} catch (PDOException $e) {
echo '{"error":{"text":' . $e->getMessage() . '}}';
}
}
示例14: getInstance
public static function getInstance()
{
if (Connection::$connection === NULL) {
// connect to the database
$host = "localhost";
//logging into the database
$db = "highland_books_database";
$user = "JamieUser";
$password = "Jamie";
$dsn = "mysql:host=" . $host . ";dbname=" . $db;
Connection::$connection = new PDO($dsn, $user, $password);
if (!Connection::$connection) {
die("Could not connect to database");
}
}
return Connection::$connection;
}
示例15: descargaApk
function descargaApk($array)
{
try {
if ($array != NULL) {
$con = new Connection();
$mysql = $con->connection();
$this->sql = "SELECT\n\t\t\t\taplicativo.ubicacion\n\t\t\t\tFROM usuarios\n\t\t\t\tINNER JOIN permisos on permisos.idUsuario = usuarios.id\n\t\t\t\tINNER JOIN aplicativo on aplicativo.id = permisos.idAplicativo\n\t\t\t\twhere\n\t\t\t\tusuarios.id = " . $array['usu'] . "\n\t\t\t\tand\n\t\t\t\taplicativo.id = " . $array['app'] . "\n\t\t\t\tand permisos.estado = 0";
$resultado = mysql_query($this->sql);
$fila = mysql_fetch_array($resultado);
$con->disconnect($mysql);
} else {
$fila = $array;
}
} catch (Exception $e) {
echo 'Excepción capturada: ', $e->getMessage(), "\n";
}
return $fila;
}