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); }
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; }
/** * @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; }
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' => '*****@*****.**']]; $this->assertEquals($esperado, $data); }
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(); } }
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; }