top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How many ways are there to retrieve the data in result set of MySQL using PHP?

+1 vote
2,064 views
How many ways are there to retrieve the data in result set of MySQL using PHP?
posted May 16, 2014 by Mohit Sharma

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

0 votes

mysql_fetch_array - Fetch a result row as an associative array, a numeric array, or both
mysql_fetch_assoc - Fetch a result row as an associative array
mysql_fetch_object - Fetch a result row as an object
mysql_fetch_row —- Get a result row as an enumerated array

answer May 16, 2014 by Vrije Mani Upadhyay
0 votes

mysql_fetch_row()

Fetch a result row as an numeric array


<?php include('db.php'); $query=mysql_query("select * from tb"); $row=mysql_fetch_row($query); echo $row[0]; echo $row[1]; echo $row[2]; ?>

Result

1 tobby tobby78$2

mysql_fetch_object()

Fetch a result row as an object


<?php include('db.php'); $query=mysql_query("select * from tb"); $row=mysql_fetch_object($query); echo $row->id; echo $row->username; echo $row->password; ?>

Result

1 tobby tobby78$2

mysql_fetch_assoc()

Fetch a result row as an associative array


<?php include('db.php'); $query=mysql_query("select * from tb"); $row=mysql_fetch_assoc($query); echo $row['id']; echo $row['username']; echo $row['password']; ?>

Result

1 tobby tobby78$2

mysql_fetch_array()

Fetch a result row as an associative array, a numeric array and also it fetches by both associative & numeric array.


<?php
include('db.php');
$query=mysql_query("select * from tb");
$row=mysql_fetch_array($query);
echo $row['id'];
echo $row['username'];
echo $row['password'];

/* here both associative array and numeric array will work. */

echo $row[0];
echo $row[1];
echo $row[2];

?>

answer Aug 16, 2014 by anonymous
Similar Questions
+5 votes

I Know that we can always fetch from one database server and rewrite it to another. But what is the simplest way to do this?

+2 votes

I have a date field on an html form that users may leave blank. If they do leave it blank I want to write the date 01/01/1901 into the mysql table. How can I accomplish this and where in my .php script file should I put the code?

...