Categories
How do I connect to MySQL from within PHP?
$servername = "YourDbHost";
$username = "DbUserName";
$password = "DbPassword";
$conn = mysqli_connect($servername, $username, $password);
if (!$conn) {
which("Connection failed: " . mysqli_connect_error()); }echo
"Connected successfully";?>
= "YourDbHost";
$username = "DbUsername";
$password = "DbPassword";
try {
$conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password); $conn->setAttribute
(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo "
Connected successfully"; } catch(PDOException
$e) { echo "Connection
failed: " . $e->getMessage(); }?>