saul Posted August 22, 2017 Report Posted August 22, 2017 // Aceasta este oop (MySQLi Object-Oriented) <?php $servername = "localhost"; $username = "username"; $password = "password"; $dbname = ""; // Creaza conexiunea $conn = new mysqli($servername, $username, $password, $dbname); // O verifica if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } echo "Connected successfully"; // Doar daca doriti sa verificati daca a fost facuta cu succes ! ?> --? PDO , avantajul la pdo ca suporta si alte tipuri de baza de date , mysqli suportant doar mysql. <?php $servername = "localhost"; $username = "username"; $password = "password"; try { $conn = new PDO("mysql:host=$servername;dbname=AICIBDNAME", $username, $password); // seteaza modul prin care sa iti arata erorile. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo "Connected successfully"; } catch(PDOException $e) { echo "Connection failed: " . $e->getMessage(); } ?>
Recommended Posts