$sql = "SELECT id, firstname, lastname FROM MyGuests";
$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";
}
$conn->close();
<?php
// MySqli connection
$mysqli = new mysqli("localhost", "my_username", "my_password", "my_database");
// Errors
if($mysqli->connect_error) {
echo "<b>Failed to connect to MySQL: </b>" . $mysqli->connect_error;
}
// Query
$selectQuery = $mysqli->prepare("SELECT * FROM my_table");
$selectQuery->execute();
$selectQueryResult = $selectQuery->get_result();
// Loop
while($selectQueryRow = $selectQueryResult->fetch_array()) {
echo $selectQueryRow['my_column'];
}
// Example
$selectUsername = $mysqli->prepare("SELECT * FROM users");
$selectUsername->execute();
$selectUsernameResult = $selectUsername->get_result();
while($selectUsernameRow = $selectUsernameResult->fetch_array()) {
echo $selectUsernameRow['username'];
}
xPawSourceQueryExceptionInvalidPacketException: Failed to read any data from socket in C:xampphtdocsminecraftvendorxpawphp-source-query-classSourceQueryBaseSocket.php:50
Stack trace:
#0 C:xampphtdocsminecraftvendorxpawphp-source-query-classSourceQuerySocket.php(76): xPawSourceQueryBaseSocket->ReadInternal(Object(xPawSourceQueryBuffer), 1400, Array)
#1 C:xampphtdocsminecraftvendorxpawphp-source-query-classSourceQuerySourceQuery.php(212): xPawSourceQuerySocket->Read()
#2 C:xampphtdocsminecraftView.php(27): xPawSourceQuerySourceQuery->GetInfo()
#3 {main}