What is the appropriate way to use an "include" function instead of revealing the DB Username and PW? I would like to replace the three lines after //make connection with some sort of Include that refers to a PHP connection file.
The Code now:
Code: Select all
<?php
//make connection
mysql_connect ("localhost", "USER","PW")
or die ('I cannot connect to the database because: ' .mysql_error());
mysql_select_db ("Name") or die ('I cannot connect to the db because: ' .mysql_error());
//build query
$query = mysql_query("SELECT * FROM Centers where City like '$City'")
or die ('cannot select table:' .msql_error());
echo "<table border=\"1\" width=\"930\" >";
echo "<tr><th width=\"145\">Name</th>";
echo "<th width=\"145\">Address</th>";
echo "<th width=\"20\">Phone</th>";
echo "<th width=\"300\" class=\"wraptext\" >Email</th>";
echo "<th width=\"300\" class=\"wraptext\" >Website</th></tr>";
//display results
while ($row =mysql_fetch_array($query)){
echo "<tr><td>";
echo $row['Name'];
echo "</td><td>";
echo $row['Address'];
echo "</td><td>";
echo $row['Phone'];
echo "</td><td>";
echo $row['Email'];
echo "</td><td>";
echo $row['Website'];
echo "</td></tr>";
}
echo "</table>";
?>
Code: Select all
<?
DEFINE ('DB_USER', 'USER');
DEFINE ('DB_PSWD', 'PW');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'Name');
$dbcon = mysqli_connect(DB_HOST, DB_USER, DB_PSWD, DB_NAME);
?>