My php file connnects to my sql database , following code works
<?php
$servername = "globalxxx.com.mysql";
$username = "globalxxx_com";
$password = "YS4xxx";
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully"
$sql = "SELECT Id, FirstName, LastName FROM mydb";
$result = $conn->query($sql);
?>
after that a staff listing which is written in html shows
BUT if i use following code to get data out of my sql to display I only get a blank screen
<?php
$servername = "globalxxx.com.mysql";
$username = "globalxxx_com";
$password = "YS4xxx";
$dbname = "mydb";
$conn = new mysqli($servername, $username, $password,$dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully"
$sql = "SELECT Id, FirstName, LastName FROM mydb";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "Id: " . $row["Id"]. " - Name: " . $row["FirstName"]. " " . $row["LastName"]. "<br>";
}
} else {
echo "0 results";
}
?>
I wonder where is the problem , can sb help ? Please !!!!