Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Select some data from MySQL using PHP

This snippet basically will select some data from a MySQL table using PHP. A friend sent me a request to pull from PHPBB's tables, so this script was born.

<?php
	$UserName = "@@@@@";
	$PassWord = "$$$$$";
	$DataBase = "%%%%%";
	$HostName = "localhost"; // Unless your host is remote, use localhost.

	$MySQLConnection = mysql_connect($HostName, $UserName, $PassWord) or die("Unable to connect to MySQL Database!!");

	$MySQLSelectedDB = mysql_select_db($DataBase, $MySQLConnection) or die("Could not Set the Database!!");

	$MySQLRecordSet = mysql_query("SELECT TOP 5 field_1, field_2 FROM some_phpbb_table");

	while ($MyRow = mysql_fetch_array($MySQLRecordSet, MYSQL_ASSOC)) {
		print "First Field: " . $MyRow{'field_1'} . " Second Field: " . $MyRow{'field_2'} . "<br>";
	}
	mysql_close($MySQLConnection);
}
?>
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS