Database connection

PHOTO EMBED

Tue Jul 26 2022 12:08:18 GMT+0000 (Coordinated Universal Time)

Saved by @patdevwork

<?php

// This guide demonstrates the five fundamental steps
// of database interaction using PHP.

// Credentials
$dbhost = '';
$dbuser = '';
$dbpass = '';
$dbname = '';

// 1. Create a database connection
$connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);

// 2. Perform database query
$result_set = mysqli_query($connection, $query)
//example of a function for selecting all
function select_all() {
        global $db;
        $sql = "SELECT * FROM subjects ";
        $sql .= "ORDER BY position ASC";
        $result = mysqli_query($db, $sql);
        return $result;
    }
 
// 3. Use returned data (if any)

// 4. Release returned data

// 5. Close database connection
mysqli_close($connection);

?>
content_copyCOPY