Before you can get content out of your MySQL database, you must know how to establish a connection to MySQL from inside a PHP script. To perform basic queries from within MySQL is very easy. This article will show you how to get up and running.
Let's get started. The first thing to do is connect to the database.The function to connect to MySQL is called mysql_connect. This function returns a resource which is a pointer to the database connection. It's also called a database handle, and we'll use it in later functions. Don't forget to replace your connection details.
Example:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "studentList";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//
?>
Let's get started. The first thing to do is connect to the database.The function to connect to MySQL is called mysql_connect. This function returns a resource which is a pointer to the database connection. It's also called a database handle, and we'll use it in later functions. Don't forget to replace your connection details.
Example:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "studentList";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//
?>
HEY!
ReplyDeleteNICE BLOG,YOUR BLOG IS REALLY USEFUL FOR ME,KEEP POSTING.
PYTHON FULL STACK IN KUKATPALLY
I would like to appreciate you for making it very simple and easy
ReplyDeleteRegards,
Java Full Stack in KPHB