A shortened version of weblog.

A shortened version of weblog.

PHP MySQL Select Data

  • Programming
  • 19 June 2022
  • 1579 Views
  • Sathiyamoorthy V

1. PHP MySQL Select Data ( MySQLi Object-Oriented )

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

$sql = "SELECT * 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();
?>

2. PHP MySQL Select Data ( MySQLi Procedural )

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);

$sql = "SELECT * FROM MyGuests";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0)
{
// output data of each row
while($row = mysqli_fetch_assoc($result))
{
echo "id: " . $row['id']. " - Name: " . $row['firstname']. " " . $row['lastname']. "<br>";
}
}
else
{
echo "0 results";
}

mysqli_close($conn);
?>

RELATED POST

10 June 2022   |   Programming
PHP MySQL Insert Data
Read More
10 June 2022   |   Programming
PHP MySQL Create Table
Read More
10 June 2022   |   Programming
PHP Create a MySQL Database
Read More
20 September 2022   |   Programming
IoT - Internet of Things Presentations & Programming Materials
Read More
29 May 2023   |   Programming
MySQL vs. MongoDB: What is the Difference?
Read More
29 August 2023   |   Programming
Introduction of GitHub
Read More
PHP MySQL Select Data
https://blogbyte.in/blog-details/?cid=2&pid=38

LEAVE A COMMENT

+