Cheers Roel, I already downloaded the code from Wrox, thats what I was trying to use.
Must be something else I am missing or doing wrong. Thanks anyway. "Roel Mulder" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > At 11:31 29-11-2001 +0000, you wrote: > >Thanks for the reply's, > > > >I am still not to clear as what is wrong with my origianl syntax. > > There is possibly nothing wrong as long as it works :) and already it is > clear that debugging isn't too straightforward > > >I could use these different ideas, but I am really trying to debug the > >original script I sent. I got the example from Beginning PHP book by wrox. > > Wrox offers the scripts it publishes in it's book online, > http://www.wrox.com/Books/Books.asp?section=11_3&order=title and likely > this is the code used in the book: > http://www.wrox.com/Books/Book_down.asp?section=11_3&isbn=1861003730&subject =&subject_id= > > this in case you typed it from the book yourself, this download could > eliminate typo's. > > > > > >----- Original Message ----- > > > > >From: Ian <[EMAIL PROTECTED]> > > > > >To: <[EMAIL PROTECTED]> > > > > >Sent: Wednesday, November 28, 2001 5:52 PM > > > > >Subject: [PHP-DB] db connect problems. > > > > > > > > > > > > > > > > Hello, wonder if anyone can debug this script. > > > > > > > > > > > > I copied it from an example in a book. > > > > > > > > > > > > There is a .php file and a .inc file > > > > > > > > > > > > This is the .inc file: > > > > > > > > > > > > <?php > > > > > > file://common_db.inc > > > > > > $dbhost = 'localhost'; > > > > > > $dbusername = 'root'; > > > > > > $dbuserpassword = ''; > > > > > > $default_dbname = 'mysql'; > > > > > > $MYSQL_ERRNO = ''; > > > > > > $MYSQL_ERROR = ''; > > > > > > function db_connect($dbname="") { > > > > > > global $dbhost, $dbusername, $dbuserpassword, $default_dbname, > > > $dbname; > > > > > > global $MYSQL_ERRNO, $MYSQL_ERROR; > > > > > > $link_id = mysql_connect($dbhost, $dbusername, $dbuserpassword); > > > > > > if(!$link_id) { > > > > > > $MYSQL_ERRNO = 0; > > > > > > $MYSQL_ERROR = "Connection failed to the host $dbhost."; > > > > > > return 0; > > > > > > } > > > > > > else if(empty($dbname) && !mysql_select_db($default_dbname)) { > > > > > > $MYSQL_ERRNO = mysql_errno(); > > > > > > $MYSQL_ERROR = mysql_error(); > > > > > > return 0; > > > > > > } > > > > > > else return $link_id; > > > > > > } > > > > > > function sql_error() { > > > > > > global $MYSQL_ERRNO, $MYSQL_ERROR; > > > > > > if(empty($MYSQL_ERROR)) { > > > > > > $MYSQL_ERRNO = mysql_errno(); > > > > > > $MYSQL_ERROR = mysql_error(); > > > > > > } > > > > > > return "$MYSQL_ERRNO: $MYSQL_ERROR"; > > > > > > } > > > > > > ?> > > > > > > > > > > > > > > > > > > the .php file is like this: > > > > > > > > > > > > <?php > > > > > > file://show_more_db.php > > > > > > include "./common_db.inc"; > > > > > > $link_id = db_connect('sample_db'); > > > > > > $result = mysql_query("SELECT * FROM user", $link_id); > > > > > > while($query_data = mysql_fetch_row($result)) { > > > > > > ?> > > > > > > <?php > > > > > > echo "'",$query_data[1],"' is also php ' known as > > > ",$query_data[3],"<P>"; > > > > > > } > > > > > > ?> > > > > > > > > > > > > Sorry about poxy formatting, hope it is legible. > > > > > > > > > > > > I seem to have a problem passing the database to the db_connect() > > > function > > > > > > within the .php script. > > > > > > The $default_dbname variable within the .inc file is always selected > > > > >instead > > > > > > of the argument I pass. > > > > > > > > > > > > Anyone help me please? > > > > > > > > > > > > Ta. > > > > > > > > So, where or how do you pass a database to the db_connect() function? The > variable $default_dbname is declared in the include thus that one is used. > If you have a hosted site and haven't got access to the database > 'mysql' then rename the $default_dbname in the inc file to the one you > _can_ access. > Then the question is if you have the table sample_db in that database, for > it has to be there for your script to be able to retrieve data from it... > > Hope this helps, bye for now. > > Roel Mulder > > Mulder Technisch Advies > Postbus 69 > NL-2740 AB WADDINXVEEN > tel. 0182-640184 fax. 0182-640185 > http://www.mta.nl > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]