本文整理汇总了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;
}