- mysql_connect : to connect the mysql server with apache server
- mysql_select_db : to connect to a particular database in the mysql server
- mysql_query : to fire a query in the database.
- mysql_num_rows to find the number of records in a recordset which is derived from query fired.
- mysql_fetch_array to fetch array from record set.
- mysql_fetch_assoc to fetch row from associative array.
- mysql_fetch_row to fetch row from record set.
- mysql_fetch_object to fetch the data as object generally use to fetch large data
- mysql_close close mysql connection
Using while loop
$recordset = mysql_query("select * from DBTABLE");
while ($record= mysql_fetch_array($recordset ) {
echo "user_id: ".$record["db_field_name"]."<br />\n"; // as in database
echo "user_id: ".$record[0]."<br />\n"; // in key value as in array
}
This will fetch the database values from dbtable and retrieve list of particular db_field_name
Using for while loop and mysql_fetch_object
$recordset = mysql_query("select * from DBTABLE");
while ($record= mysql_fetch_object($recordset )) {
echo $record->db_field_name;
}
Using for loop
$record= mysql_fetch_array($recordset );
$count=count($record) ;
for($i = 0;$i< $count ; $i ++)
{
echo "user_id: ".$record[$i]["db_field_name"]."<br />\n"; // as in database
}
we will go through other function later...