ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

In how many ways we can retrieve the data in the result set of MySQL using PHP?

user-image
تم إضافة السؤال من قبل Zaid Rabab'a , Software Development Team Leader , Al-Safa Co. Ltd.
تاريخ النشر: 2013/04/02
Faizan Ahmad
من قبل Faizan Ahmad , Software Engineer , cardekho.com

1 ) mysql_fetch_row() : The mysql_fetch_row() function returns a row from a resultset as a numeric array.
This function gets a row from the mysql_query() function and returns an array on success, or FALSE on failure or when there are no more rows.
mysql_fetch_row() fetches one row of data from the result associated with the specified result identifier.
The row is returned as an array.
Each result column is stored in an array offset, starting at offset 0.
2) mysql_fetch_array(): The mysql_fetch_array() function fetches a result row as an associative array or a numeric array or using both the ways.
3) mysql_fetch_object(): The mysql_fetch_object() function fetches a result row as an object.
4)mysql_fetch_assoc(): The mysql_fetch_assoc() function fetches a result row as an associative array.

marwa khalaf
من قبل marwa khalaf , .Net Developer , Sands National Academy

1.
mysql_fetch_row.
2.
mysql_fetch_array 3.
mysql_fetch_object 4.
mysql_fetch_assoc

The answer for your question is:-

 

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.

<?phpinclude('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];

?>

Source:  How many ways are there to retrieve the data in result set of MySQL

المزيد من الأسئلة المماثلة