Skip to content

Instantly share code, notes, and snippets.

@asathoor
Created September 19, 2017 09:37
Show Gist options
  • Save asathoor/212763e3a1683443f571ffc96f28de79 to your computer and use it in GitHub Desktop.
Save asathoor/212763e3a1683443f571ffc96f28de79 to your computer and use it in GitHub Desktop.
Mysql_cnt1
<?php
// CONNECT TO THE SAKILA DATABASE
$mysqli = new mysqli(
"localhost",
"root",
"mojndo",
"forta_cnt1"
); // creates the object
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") "
. $mysqli->connect_error; // if error messages
}
/* test your connection */
echo "Your're connected to the database via: "
. $mysqli->host_info
. "\n";
$sql = "SELECT * FROM `customers` ORDER BY `cust_name` DESC";
$result = $mysqli->query($sql); // query
?>
<h2>Kunder</h2>
<?php
// looping out the result
while($row = $result->fetch_assoc()){
echo $row['cust_name'] . " -- ";
}
mysqli_close($mysqli);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment