That should definitely be working. Only thing I can think of is that you're database name isn't correct. You're certain "news" is the full name of the database.. I mean it's not "news_com" or something like that? The $link must be valid becuase the script isn't ending with "Couldn't make connection". So that just leaves the mysql_select_db() function. And the only thing that will make that function return FALSE is if it can't find the database name for that user on the specified server. -Kevin
----- Original Message ----- From: "Matthew Bielecki" <[EMAIL PROTECTED]> To: "PHPCoder" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Cc: "php-general" <[EMAIL PROTECTED]> Sent: Wednesday, July 24, 2002 2:07 PM Subject: Re: [PHP] Help with msql_fetch_array() > Well I think you were correct about not connecting to the db, but I don't > understand why. I wrote another little script just to test the > connection. > > <?php > > $link = mysql_connect("servername","username","password") > or die("Couldn't make connection."); > $diditwork = mysql_select_db("news", $link); > > if ($diditwork <> FALSE) > { > echo "got the db..yeahhhh!"; > echo $link; > } > else > { > echo "didnt get db...booooo"; > echo $link; > } > ?> > > This returns "didnt get db...booooooResource id #1 > > I don't understand how I can get a resource ID but then not be able to use > the "news" database. Like I described earlier, this happens with my other > db as well. I can connect to the db through the console or any other > client I have on the physical server and do whatever I want with the db's, > I'm just having problems with php. > > Thanks again for your help!! > > > > > > > > > > PHPCoder <[EMAIL PROTECTED]> > 07/24/02 01:50 PM > > > To: Matthew Bielecki <[EMAIL PROTECTED]> > cc: php-general <[EMAIL PROTECTED]> > Subject: Re: [PHP] Help with msql_fetch_array() > > > I can almost guarantee that it's not the second line that is "failing", > the problem here is that $result is not containing naything, and that is > normally due to the fact that you are not connecting to the db, or the > table "tablename" is not there. > > I use the following format as my "standard" MySQL connect and query > snippet: > > $link = @mysql_connect("localhost",$username,$password) or die ('Could > not connect!'); //@ suppresses the default error message generated by > this function and the "or die()" bit kills the script right then and > there should it not be able to connect. > mysql_select_db("YOUR_DB_NAME",$link); > $sql = "select * from your_table_name"; > if ( $result = mysql_query($sql)) { // checks to see if $result > contains anything before it even tries to fetch an associative array > from it. > $row = mysql_fetch_assoc($result); > } else { > echo "Empty result set!"; > > Note also that I use mysql_fetch_assoc and NOT mysql_fecth_array, as 9 > out of 10 times, you don't need the array element id's that is returned > by mysql_fetch_array. > > Matthew Bielecki wrote: > > >I have a couple of scripts that fail with the error of: > >Warning: mysql_fetch_array(): supplied argument is not a valid MySQL > result > >resource in... > > > >I'm new to both SQL and PHP and I'm wondering if I have some setting > >turned off or what. > > > >Here's the piece of code that is failing (the second line fails): > > > >$result = mysql_db_query($dbname, "SELECT * FROM tablename ORDER BY id"); > > $row = mysql_fetch_array($result); > > > > > >Thanks for your help in advance!! > > > > > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php