begginer's simple PHP select statment

This is a discussion on begginer's simple PHP select statment within the PHP Language forums, part of the PHP Programming Forums category; I need help on my basic table connection syntaxt using PHP. I call the php from a web browser url_name_goes_here/...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-20-2004
Alex Glaros
 
Posts: n/a
Default begginer's simple PHP select statment

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
table.

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?

Thanks!

Alex Glaros

EXAMPLE 1 (from within MySQL - this works correctly)
--------------------------------------------------------------------------------------------------------------------------------------------------------------

/usr/local/mysql3/bin/mysql -h db1.pacific.net -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 = 'db1.pacific.net';
$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]";
}
mysql_close($db_connect);
?>

HERE'S THE ERROR MESSAGE I GET:
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)

<?php
mysql_connect("db1.pacific.net", "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";
}
mysql_free_result($result);
?>

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:45 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0