Last active
December 25, 2021 09:36
-
-
Save itswadesh/dbf27ce1ea3a34f027124526d0661412 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 | |
class Database { | |
private $host = "localhost"; | |
private $user = "root"; | |
private $password = "root"; | |
private $database = "crud"; | |
function runQuery($sql) { | |
$conn = new mysqli($this->host,$this->user,$this->password,$this->database); | |
if ($conn->connect_error) { | |
die("Connection failed: " . $conn->connect_error); | |
} | |
$result = $conn->query($sql); | |
if ($result->num_rows > 0) { | |
while($row = $result->fetch_assoc()) { | |
$resultset[] = $row; | |
} | |
} | |
$conn->close(); | |
if(!empty($resultset)) | |
return $resultset; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment