begginer's simple PHP select statment

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

I need help on my basic table connection syntaxt using PHP.   I call
the php from a web browser   url_name_goes_here/test.php. The database
name is tennis and the user name is tennis.

If I type the commands directly from the MySQL> mode, my access works
fine (see example 1 below).   But when I try to access the table from
PHP, I have a syntaxt problem (see example 2 below).   Can anyone
please type up the correct PHP syntaxt for me?  The 3rd example works
but I don't know how to translate that into a select statement for the

Finally, after I get it working, how do I keep my password out of
sight? if I forgot to put an index file in the directory, wouldln't all
of the files be visible from a surfer's browser?


Alex Glaros

EXAMPLE 1 (from within MySQL - this works correctly)

/usr/local/mysql3/bin/mysql -h -u tennis -p
Enter password: ( get prompted for my password here, then sucessfully
get to mysql> prompt)
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 123456 to server version: 3.23.57
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> use tennis
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from tourneys;
| tourney_id | tourney_name     | minutes_per_game | td_id |
multi_venued_y_or_n | date_tourney_begins | date_tourney_ends

Then I get all the rows for table tourneys correctly displayed

EXAMPLE 2 (Web browser calls PHP - this doesn't work)

$db_username = 'tennis';
$db_password = 'mypassword';
$db_hostname = '';
$db_connect = mysql_connect($db_hostname, $db_username, $db_password)or
die("Unable to connect to MySQL");
$db_select = mysql_select_db('tourneys', $db_connect)or die("Unable to
select tourneys");
while ($row = mysql_fetch_array($result)) {
printf "$row[tourney_id] $row[tourney_name] $row[td_id]";

Parse error: parse error, unexpected '\"' in
/server_path_name/public_html/test.php on line 8

EXAMPLE 3  (Web browser calls PHP - this does work but I don't know how
to get the select statement above to work)

mysql_connect("", "tennis", "mypassword");
$result = mysql_list_tables("tennis");
$num_rows = mysql_num_rows($result);
for ($i = 0; $i < $num_rows; $i++) {
echo "Table: ", mysql_tablename($result, $i), "\n";

Site Timeline