samedi 26 septembre 2015

php read data from sql database

So, I'm trying to learn php and I can't read any data from my database! I know the connection to the server is live and working but this line seem to be giving me problems

$result = $conn->query($sql);

Where $sql = "SELECT firstName, middleName, lastName FROM Base"; I'm not sure what the problem is but any hints or answer are appreciated

<!DOCTYPE html>
<html>
<head>
</head>
<body>

<h1>My first PHP page</h1>

<?php



//connect to database
$user_name = "superUser";
$password = "";
$database = "Base"
$server = "127.0.0.5";

//open connection to the server
$conn = new mysqli($server, $user_name, $password);
//echo "Connection to the server is open";

//check connetion
if($conn->connect_error)
{
    die("Connection failed: " . $conn->connect_error);
}else
{
    print "Connection to the server is open";
}

//load the data from the table
$sql = "SELECT firstName, middleName, lastName FROM Base";
//echo $conn->server_info;
$result = $conn->query($sql);


if($result)
{
    echo "Table was found";
}
else
    echo "no";

/*while($row = $result->fetch_assoc()) {
    echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
}
print $result["firstName"];// ": Number of Rows!" ;*/


//if ($result->num_rows > 0) {
// output data of each row



//close server connection
$conn->close();
?>

</body>
</html>




Aucun commentaire:

Enregistrer un commentaire