gdejong
03-13-2007, 01:06 PM
Help!
I don't consider myself a newbie with MySQL, but the PHP-MySQL connection is baffling me! So here is my PHP newbie question: When I try to access already built and populated database tables from my subdomain and run the following code fragment from my browser, I get no exceptions but the only thing echoed *verbatim* is the items following the "0)" in the conditional if statement. When I try to remotely access the database it Pings but no connection. I have created a user with "?" as host, and have tried every combination of username, password, hostname from the administrator access on down. What dunderheaded thing am I doing wrong?
$host = "localhost";
//...or "?" or URL, both ours and APIS
$user = "gdejong";
// ...or any defined users
$pass = "";
// ...or any pre-established p/w
$db = "oldmilwaukee_buildings";
// this is the only db, it doesn't work with table names either
// open connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
// create query
$query = "SELECT * FROM buildings";
// execute query
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
// see if any rows were returned
if (mysql_num_rows($result) > 0) {
echo "<table cellpadding=10 border=1>";
while($row = mysql_fetch_row($result)) {
echo "<tr>";
echo "<td>".$row[0]."</td>";
// etc.....
Since I am a newbie to PHPI am probably missing something--magic quotes? session variables? --I am at a loss. Thanks beforehand...
I don't consider myself a newbie with MySQL, but the PHP-MySQL connection is baffling me! So here is my PHP newbie question: When I try to access already built and populated database tables from my subdomain and run the following code fragment from my browser, I get no exceptions but the only thing echoed *verbatim* is the items following the "0)" in the conditional if statement. When I try to remotely access the database it Pings but no connection. I have created a user with "?" as host, and have tried every combination of username, password, hostname from the administrator access on down. What dunderheaded thing am I doing wrong?
$host = "localhost";
//...or "?" or URL, both ours and APIS
$user = "gdejong";
// ...or any defined users
$pass = "";
// ...or any pre-established p/w
$db = "oldmilwaukee_buildings";
// this is the only db, it doesn't work with table names either
// open connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
// create query
$query = "SELECT * FROM buildings";
// execute query
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
// see if any rows were returned
if (mysql_num_rows($result) > 0) {
echo "<table cellpadding=10 border=1>";
while($row = mysql_fetch_row($result)) {
echo "<tr>";
echo "<td>".$row[0]."</td>";
// etc.....
Since I am a newbie to PHPI am probably missing something--magic quotes? session variables? --I am at a loss. Thanks beforehand...