Jump to content

Conectare baza de date Mysqli


saul

Recommended Posts

// 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();
    }
?> 

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.