Created
July 1, 2020 11:00
-
-
Save viralvadgama/6a0852aaae0e040bf8185f60c0daf6a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Database credentials | |
$_servername = "localhost"; | |
$_username = "root"; | |
$_password = ""; | |
$_dbname = "location_db"; | |
// Create connection | |
$_conn = @new mysqli($_servername, $_username, $_password, $_dbname); | |
// Check connection | |
if ($_conn->connect_error) { | |
die("Connection failed: " . $conn->connect_error); | |
} | |
// For getting multiple records from database | |
function get_records($query = "") { | |
global $_conn; | |
$result = $_conn->query($query); | |
if (!$result) { | |
die("Error: " . $_conn->error); | |
} | |
$query_result = []; | |
while ($row = $result->fetch_assoc()) { | |
$query_result[] = $row; | |
} | |
return $query_result; | |
} | |
// For getting single record from database | |
function get_record($query = "") { | |
global $_conn; | |
$result = $_conn->query($query); | |
if (!$result) { | |
die("Error: " . $_conn->error); | |
} | |
return $result->fetch_assoc(); | |
} | |
// For fireing query from database | |
function fire_query($query = "") { | |
global $_conn; | |
$result = $_conn->query($query); | |
if (!$result) { | |
die("Error: " . $_conn->error); | |
} | |
return $_conn->affected_rows; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$_conn->close();