RE: [PHP] mysql problems
| From: | Narvaez, Teresa | Date: | Wed, 13 Mar 2002 01:39:09 +0000 |
| Subject: | RE: [PHP] mysql problems | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-88280@lists.php.net to get a copy of this message | ||
I agree with Hugh. I think it is always a good idea to check for return
values of any function call. So, I'd replace this line:
$result = mysql_query("select * from table");
with
$result = mysql_query("select * from table");
or die("Unable to connect to SQL server: ". mysql_error());
-Teresa
-----Original Message-----
From: hugh danaher [mailto:hdanaher@earthlink.net]
Sent: Tuesday, March 12, 2002 8:27 PM
To: Maarten Weyn; php
Subject: Re: [PHP] mysql problems
Maarten,
Perhaps "table" isn't the name of the table you want.
If mysql can't find the table (in line 13?), your $result variable is empty
and this causes (line 17?) to fail also.
Hope this helps,
Hugh
----- Original Message -----
From: "Maarten Weyn" <maarten.weyn@wesdec.com>
To: <php-general@lists.php.net>
Sent: Tuesday, March 12, 2002 5:19 PM
Subject: [PHP] mysql problems
> Hi on this code:
>
> $link = mysql_connect("localhost", "login", "passwd");
> mysql_select_db("table");
> $result = mysql_query("select * from table");
> while ($row = mysql_fetch_object($result)) {
> echo $row->ID;
> echo $row->Drank;
> }
> mysql_free_result($result);
>
> mysql_close($link);
>
> It resulst in
> Warning: Supplied argument is not a valid MySQL result resource in
> c:\program files\apache group\apache\htdocs\index.php on line 13
> Warning: Supplied argument is not a valid MySQL result resource in
> c:\program files\apache group\apache\htdocs\index.php on line 17
>
> line 13 = while ($row = mysql_fetch_object($result)) {
> line 17 = mysql_free_result($result);
>
> I'm running an Apache/1.3.23 on a win 2000 with PHP Version 4.1.2 and
mysql
> 3.23.39.
>
>
> Does it not recoginze this mysql_... statements?
>
>
> Maarten
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php