MySQL Improved provide us with two methods for accessing MySQL Database:

  • Procedural approach
  • Object-oriented approach

A typical Example is shown below of using procedural approach

# Connecting and selecting a database
$db = mysqli_connect(‘host_machine’, ‘your_username’, ‘your_password’);
if (!$db) {
die(“Connection failed: ” . mysqli_connect_error());
}else{
echo “Connected successfully”;
}

# Retrieve records from the database
$sqlInsert = “SELECT column_name(s) FROM table_name”;
$statement = mysqli_query($db, $sqlInsert);

# Display the result
if (mysqli_num_rows($statement ) > 0) {
while($rs = mysqli_fetch_assoc($statement )) {
echo “id: ” . $rs[“id”];
}
} else {
echo “No record found”;
}

#close the connection
mysqli_close($db);

MySQL Improved

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: