Introduction
MySQL is a popular free and open-source database management system. MariaDB is a fork of MySQL.
Both are widely used for web applications. PHP can be used to interact with MySQL / MariaDB databases.
DBMS service is a standalone service that is NOT related to PHP / Web server.
You can interact with DBMS using any DBMS client (e.g. DBeaver) including programming languages like PHP, Python, Java, etc.
After connected to DBMS,
SQL is used to interact with databases.
Source: techopedia.com
Code - Connect to database server
<?php
// Database server information
$servername = "10.103.145.240";
$username = "studentlocal";
$password = "studentlocal";
$dbname = "login";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} else {
echo "Connected successfully";
}
?>
Code - Get data with SQL
<?php
// Database server information
$servername = "10.103.145.240";
$username = "studentlocal";
$password = "studentlocal";
$dbname = "login";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} else {
// if connected successfully
$sql = "SELECT * FROM accounts";
// execute the SQL and store output in $result
$result = $conn->query($sql);
// display content in $result
print_r($result->fetch_all());
}
?>