Skip to content
Snippets Groups Projects
Commit 043eae18 authored by Sibidharan's avatar Sibidharan :speech_balloon:
Browse files

Database Connection Library

parent 95e1dd07
No related branches found
No related tags found
No related merge requests found
.DS_Store 0 → 100644
File added
<?php
$db_conn = NULL;
$db_username = 'lahtp';
$db_password = 'virtualhostx';
$db_servername = 'localhost';
$db_name = 'lahtp_3_web';
function get_db_connection() {
global $db_conn;
global $db_servername;
global $db_username;
global $db_password;
global $db_name;
if($db_conn != NULL){ //check if an existing connection is open
return $db_conn; //return the existing connection
} else { //make a new connection
$db_conn = mysqli_connect($db_servername, $db_username, $db_password, $db_name);
if(!$db_conn){
die("Connection failed: ".mysqli_connect_error());
} else {
return $db_conn;
}
}
}
function do_login($username, $password){
$query = "SELECT * FROM lahtp_3_web.auth WHERE username='$username' AND password='$password';";
$connection = get_db_connection();
$result = mysqli_query($connection, $query);
return mysqli_num_rows($result);
}
\ No newline at end of file
<?php
include 'library/auth.php';
if(do_login('sibi', 'passwddord')){
echo "Success";
} else {
echo "Failed";
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment