Monday, May 13, 2013

Explain the ways to retrieve the data in the result set of MySQL using PHP


1. mysql_fetch_row($result):- where $result is the result resource returned from a successful query executed using the mysql_query() function.
Example:
$result = mysql_query(“SELECT * from students);
while($row = mysql_fetch_row($result))
{
      Some statement;
}
2. mysql_fetch_array($result):- Return the current row with both associative and numeric indexes where each column can either be accessed by 0, 1, 2, etc., or the column name.

Example:
$row = mysql_fetch_array($result)
3. mysql_fetch_assoc($result): Return the current row as an associative array, where the name of each column is a key in the array.

Example:
$row = mysql_fetch_assoc($result)
$row[‘column_name’]

No comments:

Post a Comment