A shortened version of weblog.

A shortened version of weblog.

PHP MySQL Select Data

  • Programming
  • 19 June 2022
  • 36061 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
PHP MySQL Select Data
https://blogbyte.in/blog-details/?cid=2&pid=38
  COMMENTS ( 4 )
Comment
Http://Boyarka-inform.com/

Inspiring quest there. What happened after? Good luck! http://Boyarka-inform.com/

 13-07-2025   1:19:PM
Comment
Gilbert

Its such as you read mmy thoughts! You appear to grasp a lot approximately this, lik you wrtote tthe book iin it or something. I feel that you simply can do with some % to force the message house a bit, but other tnan that, tnis is wonderful blog. A fantastic read. I will certainly be back. http://boyarka-inform.com/

 12-07-2025   11:51:AM
Comment
Http://Boyarka-Inform.com

Wonderful article! That is the type of information that are meant to be shared around the web. Shame on Google for now not positioning this post higher! Coome on over and visit my website . Thanks =) http://Boyarka-Inform.com

 20-06-2025   4:12:PM
Comment
Epifania

What Freud Can Teach Us About Adultwork Pornstar porn Stars

 01-01-2025   5:29:PM

LEAVE A COMMENT

+