ICC WORLD CUP 2011 WATCH LIVE ONLINE

How to access database using PHP

1:32 PM Posted by: Isuru Jayathissa 0 comments

$db = "Netplexer"; // Here name of the database

$link = mysql_connect("localhost","root","" ); // Setp 1 , connection... .
// here I use default setting of Mysql database

if ( ! $link )

die( "Couldn't connect to MySQL" ); // error massage


mysql_select_db( $db, $link ); // Step 2 , select database
or die ( "Couldn't open : ".mysql_error() );

$query = "SELECT DST_IP,// Step 3 , Mysql query ,
COUNT(DST_IP) AS NumOccurrences
FROM IncomingTraffic
GROUP BY DST_IP
HAVING ( COUNT(DST_IP) > 1 )
ORDER BY NumOccurrences DESC";


// here we can use Select , Insert , drop , etc ..

$result=mysql_query( $query) or die (mysql_error());
$i=0;

while($row=mysql_fetch_array($result)) // separate data using arrays
{

$data []= $row['NumOccurrences'];
$dataIP []= $row['DST_IP'];

}

mysql_close( $link ); // Step 4 , Close

No comments:

Post a Comment

 


2009 Isuru's Blog. All rights reserved.
.
For the more details..,
keijayathissa@gmail.com