Answers for "php connection with mysql"

PHP
18

php sql connection

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn= mysqli_connect($servername,$username,$password,$dbname);
// Check connection
if (!$conn) {
  die("Connection failed: " . mysqli_connect_error());
}
echo "Connected Successfully.";
?>
Posted by: Guest on May-11-2020
1

mysql connect php

# MySql improved
<?php
    $mysqli = new mysqli("localhost", "username", "password", "dbname");
	$result = $mysqli->query("SELECT lastname FROM employees");
?>
# Connection with PDO
<?php
    $myPDO = new PDO('mysql:host=localhost;dbname=dbname', 'username', 'password');
	$result = $myPDO->query("SELECT lastname FROM employees");
?>
# With PHP legacy functions:
<?php
    mysql_connect('localhost','username','password');
    mysql_select_db("dbname");
	$result = mysql_query('SELECT lastname FROM employees');
?>
Posted by: Guest on March-20-2021
1

how to connect to a database in php

<?php
$servername = "localhost";
$username = "username";
$password = "password";

// 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 November-10-2019

Code answers related to "php connection with mysql"

Browse Popular Code Answers by Language