OOP example:
//create a connection $conn = mysqli_connect('localhost', 'root', 'password', 'testdb'); //write our SQL query to a variable $sql $sql = "SELECT * FROM Users"; if($result = $conn->query($sql)){//connect to the base foreach($result as $row){//iterate elements $userid = $row["id"]; $username = $row["name"]; $userage = $row["age"]; } }
Get data from the database by functional method:
$conn = mysqli_connect('localhost', 'root', 'password', 'testdb'); $sql = "SELECT * FROM Users"; if($result = mysqli_query($conn, $sql)){ foreach($result as $row){ $userid = $row["id"]; $username = $row["name"]; $userage = $row["age"]; } }