DZone 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
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);
}
?>





