本文整理匯總了PHP中Connection::conn方法的典型用法代碼示例。如果您正苦於以下問題:PHP Connection::conn方法的具體用法?PHP Connection::conn怎麽用?PHP Connection::conn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Connection
的用法示例。
在下文中一共展示了Connection::conn方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testConexaoAoBancoDeDados
public function testConexaoAoBancoDeDados()
{
$config = new Configurator(['dsn' => 'mysql:host=localhost;dbname=php_praticas_modernas', 'user' => 'root', 'pass' => '123', 'config' => []]);
$conn = new Connection($config);
$conn->conn();
$pdo = $conn->getConn();
$this->assertInstanceOf('PDO', $pdo);
}
示例2: __construct
public function __construct($host, $user, $pass, $db)
{
//echo date_default_timezone_set('Africa/Lagos');
$conn = mysqli_connect($host, $user, $pass, $db) or die("error");
mysqli_query($conn, "SET time_zone = '+01:00' ") or die("SET TIMEZONE FAILED");
self::$conn = $conn;
return $conn;
}
示例3: connect
/**
* @brief Function connect
* realiza a conexao.
* Utiliza strings: hostname, username, password e dbname, usando banco de dados 'mysqli', além de checar a conexao e seta-la no atributo 'conn'.
* @param void
* @return void
*/
private static function connect()
{
$conn = new mysqli(self::$hostname, self::$username, self::$password, self::$dbname);
if ($conn->connect_error) {
die("<hr> Connection failed: " . $conn->connect_error);
}
self::$conn = $conn;
}
示例4: testExecuteSelect
public function testExecuteSelect()
{
$config = new Configurator(['dsn' => 'mysql:host=localhost;dbname=php_praticas_modernas', 'user' => 'root', 'pass' => '123', 'config' => []]);
$conn = new Connection($config);
$conn->conn();
$select = new Mysql\Select();
$execute = new Execute($conn);
$execute->sql($select);
$data = $execute->findAll();
$esperado = [['id' => 1, 'name' => 'Erik', 'email' => 'contato@webdevbr.com.br']];
$this->assertEquals($esperado, $data);
}
示例5: PDO
function __construct($host, $db, $user, $pass)
{
$this->host = $host;
$this->db = $db;
$this->user = $user;
$this->pass = $pass;
try {
self::$conn = new PDO('mysql:host=' . $host . ';dbname=' . $db . ';', $user, $pass);
self::$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
}
示例6: __construct
public function __construct($host, $user, $pass, $db)
{
if (getenv('HEROKU')) {
$url = parse_url(getenv("CLEARDB_DATABASE_URL"));
$server = $url["host"];
$username = $url["user"];
$password = $url["pass"];
$db = substr($url["path"], 1);
$conn = new mysqli($server, $username, $password, $db);
mysqli_query($conn, "SET time_zone = '+01:00' ") or die("SET TIMEZONE FAILED");
self::$conn = $conn;
} else {
//echo date_default_timezone_set('Africa/Lagos');
$conn = mysqli_connect($host, $user, $pass, $db) or die("error");
mysqli_query($conn, "SET time_zone = '+01:00' ") or die("SET TIMEZONE FAILED");
self::$conn = $conn;
}
return $conn;
}