In mysqli you have to store your db_connection into a variable and have to pass in every query. Below is the complete path what you have to follow:
- Create connection with database by using host_name, user_name, password,db_name. And store connection into a variable.
- You can run any query by passing connection variable.
below code is:
<?php
$con = mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if ($password = mysqli_query ($con, "SELECT password FROM users WHERE firstname = '$username'")) {
echo "password success!";
}
else {
echo "Password fail!";
}
?>