1<?php
2$servername = "localhost";
3$username = "username";
4$password = "password";
5$dbname = "myDB";
6
7// Create connection
8$conn= mysqli_connect($servername,$username,$password,$dbname);
9// Check connection
10if (!$conn) {
11 die("Connection failed: " . mysqli_connect_error());
12}
13echo "Connected Successfully.";
14?>
1<?php
2$servername = "localhost";
3$username = "yourusername"; // For MYSQL the predifined username is root
4$password = "yourpassword"; // For MYSQL the predifined password is " "(blank)
5
6// Create connection
7$conn = new mysqli($servername, $username, $password);
8
9
10// Check connection
11
12 if ($conn->connect_error) {
13
14 die("Connection failed: " . $conn->connect_error);
15}
16
17echo "Connected successfully";
18
19?>
1In order to send data to a databse securely use prepared statements otherwise
2you can get attacked by an SQL Injection easily.
3----
4https://www.w3schools.com/php/php_mysql_prepared_statements.asp