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 in PHP by kartik
• 10,990 points
33 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 by Niroj
• 22,110 points

Related Questions In PHP

0 votes
1 answer

What is Php Mysql Database? How php connect to database?

Hello kartik, MySQL is the most popular database ...READ MORE

answered Feb 25 in PHP by Dey
90 views
0 votes
1 answer

How to check if php session is already started or not?

Hello kartik, Use session_id(), it returns an empty string ...READ MORE

answered Apr 1 in PHP by Niroj
• 22,110 points
48 views
0 votes
1 answer

How to send email using php?

Hello @kartik 1.) Download PHPMailer, open the zip file ...READ MORE

answered Apr 1 in PHP by Niroj
• 22,110 points
24 views
0 votes
0 answers
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 in PHP by Niroj
• 22,110 points
36 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 in PHP by Niroj
• 22,110 points
40 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 in PHP by Niroj
• 22,110 points
69 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 in PHP by Niroj
• 22,110 points
108 views
0 votes
1 answer

How to convert from MySQL datetime to another format with PHP?

Hello, To convert a date retrieved from MySQL ...READ MORE

answered May 19 in PHP by Niroj
• 22,110 points
24 views
0 votes
1 answer

How to Validate Form Data With PHP?

Hey @kartik, The first thing we will do ...READ MORE

answered Feb 13 in PHP by Niroj
• 22,110 points
90 views