How to retrieve or obtain data from the MySQL database using PHP

0 votes
After i had created mysql database and make connection between them. Now, how can i request data from the database using php?

thank you!!
Mar 27, 2020 in PHP by kartik
• 37,520 points
3,292 views

1 answer to this question.

0 votes

Hello kartik,

 Actually there are many functions that  are available in PHP to retrieve the data from the MySQL database.

The Function are :mysqli_fetch_array(), mysqli_fetch_row(), mysqli_fetch_assoc(), mysqli_fetch_object().

Few functions are mentioned below:

mysqli_fetch_array() – It is used to fetch the records as a numeric array or an associative array.

Sample code:

// Associative or Numeric array

$result=mysqli_query($DBconnection,$query);

$row=mysqli_fetch_array($result,MYSQLI_ASSOC);

echo "Name is $row[0]

";

echo "Email is $row['email']

";

mysqli_fetch_row() – It is used to fetch the records in a numeric array.

Sample code:

//Numeric array

$result=mysqli_query($DBconnection,$query);

$row=mysqli_fetch_array($result);

printf ("%s %s\n",$row[0],$row[1]);

mysqli_fetch_assoc() – It is used to fetch the records in an associative array.

Sample code:

// Associative array

$result=mysqli_query($DBconnection,$query);

$row=mysqli_fetch_array($result);

printf ("%s %s\n",$row["name"],$row["email"]);

mysqli_fetch_object() – It is used to fetch the records as an object.

Sample code:

// Object

$result=mysqli_query($DBconnection,$query);

$row=mysqli_fetch_array($result);

printf ("%s %s\n",$row->name,$row->email);

There are many other function that can be used to retrieve data from database for different purpose according to the user use of data.

Thank you!

answered Mar 27, 2020 by Niroj
• 82,880 points

Related Questions In PHP

0 votes
0 answers

How can I store and retrieve images from a MySQL database using PHP?

How can I insert an image in ...READ MORE

Jun 14, 2022 in PHP by narikkadan
• 63,720 points
456 views
0 votes
0 answers

How to retrieve data from multiple tables using a PHP form?

I want to retrieve data from multiple ...READ MORE

Jun 25, 2022 in PHP by narikkadan
• 63,720 points
1,885 views
0 votes
0 answers

How to filter data from a MySQL Database Table with PHP

I'm attempting to code a search box ...READ MORE

Jul 22, 2022 in PHP by narikkadan
• 63,720 points
6,570 views
0 votes
0 answers

How to fetch specific data from MySQL database to my PHP table?

I want to get data from the ...READ MORE

Jul 28, 2022 in PHP by Kithuzzz
• 38,020 points
3,184 views
0 votes
1 answer

What is meant by passing the variable by value and reference in PHP?

Hello, When the variable is passed as value ...READ MORE

answered Mar 27, 2020 in PHP by Niroj
• 82,880 points
3,210 views
0 votes
1 answer

Connection with MySQL server using PHP. How can we do that?

Hey @kartik, You have to provide MySQL hostname, ...READ MORE

answered Mar 27, 2020 in PHP by Niroj
• 82,880 points
1,241 views
0 votes
1 answer

What are the differences between mysqli_connect and mysqli_pconnect?

Hello, mysqli_pconnect() function is used for making a persistence ...READ MORE

answered Mar 27, 2020 in PHP by Niroj
• 82,880 points
3,678 views
0 votes
1 answer

How to get thumbnail of youtube video from youtube API?

Hii @kartik, If you want the biggest image ...READ MORE

answered Apr 1, 2020 in PHP by Niroj
• 82,880 points
1,601 views
0 votes
1 answer

How to export the MySql database structure without the data just the structure?

Hello @kartik, You can do with the --no-data option with ...READ MORE

answered Aug 18, 2020 in PHP by Niroj
• 82,880 points
2,556 views
0 votes
1 answer

In PHP, how to detect the execution is from CLI mode or through browser ?

Hello @kartik, Use the php_sapi_name() function. if (php_sapi_name() == "cli") { ...READ MORE

answered Oct 22, 2020 in PHP by Niroj
• 82,880 points
1,366 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP