Skip to content

Instantly share code, notes, and snippets.

@telefonosuci
Created January 17, 2018 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save telefonosuci/6866cdb664a4bea125584ba48d2b156f to your computer and use it in GitHub Desktop.
Save telefonosuci/6866cdb664a4bea125584ba48d2b156f to your computer and use it in GitHub Desktop.
PHP MySQL connection and select
<?php
// Create connection
$conn = new mysqli("localhost", "root", "");
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
mysqli_select_db($conn,"dbtest");
$sql = "SELECT * from indovina_numero";
$result = $conn->query($sql);
$A= array();
$B= array();
$C= array();
$D= array();
$E= array();
if ($result->num_rows > 0) {
// output data of each row
$i=0;
while($row = $result->fetch_assoc()) {
echo "A: " . $row["A"]. " B: " . $row["B"]. " C:" . $row["C"]. " D: ".$row["D"]." E: ".$row["E"]."<br>";
$i++;
}
} else {
echo "0 results";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment