hey guys with this i m starting new thing on my blog
as per my brother request now i ll post stuff for PHP Beginners also..
Command can be used to connect to ur server that is WAMP server
<?php
mysql_connect(“localhost”,”root”,””)or die(“can not connect to server“);
?>
To select database
<?php
mysql_select_db(“database_name”)or die(“no database found”);
?>
How to write query
<?php
$qr = “select name, class from tablename”;
?>
Its always better to write query and store it in some variable its good practice
How to execute query
<?php
$rs = mysql_query($qr)or die(mysql_error());
?>
$rs is result set obtained by query execution
now how to print result
if u r sure result is single row then
$row = mysql_fetch_row($rs);
echo “name : ”;
echo $row[0];
echo “<br>”;
echo “class : ”;
echo $row[1];
if result is more then one row then
while($row = mysql_fetch_row($rs))
{
Echo “name : ”;
echo $row[0];
echo “<br>”;
Echo “class : ”;
echo $row[1];
}
different methods to fetch data from resultset
$row = mysql_fetch_array($resultset)
different methods to fetch data from resultset
this will give result set in array and u can access this array using index or associates i.e.
$row[0]
$row[1]
$row[2]
Or
Associates
$row[‘name’]
$row[‘class’]
$row[‘rollnumber’]
$row = mysql_fetch_row($resulset)
here array can be accessed just by index
i.e.
$row[0]
$row[1]
$row[2]
$row = mysql_fetch_assoc($resultset)
Here only associates
$row[‘name’]
$row[‘class’]
$row[‘rollnumber’]
there is one more method i.e.
$row = mysql_fetch_object($resultset)
Here u can access by creating object
i.e.
$row->name;
$row->class;
…