Answers for "w3school php connect database"

PHP
1

using mysql database with php

<?php
$servername = "localhost";
$username = "yourusername"; // For MYSQL the predifined username is root
$password = "yourpassword"; // For MYSQL the predifined password is " "(blank)

// Create connection
$conn = new mysqli($servername, $username, $password);

 
// Check connection

 if ($conn->connect_error) {

    die("Connection failed: " . $conn->connect_error);
}

echo "Connected successfully";

?>
Posted by: Guest on June-01-2020
1

mysqli connect

<?php
$mysqli = new mysqli("localhost","my_user","my_password","my_db");

// Check connection
if ($mysqli -> connect_errno) {

  echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
  
  exit();

  }
?>
Posted by: Guest on November-12-2020

Browse Popular Code Answers by Language