Wrox Programmer Forums
|
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 18th, 2003, 12:48 PM
Registered User
Points: 10, Level: 1
Points: 10, Level: 1 Points: 10, Level: 1 Points: 10, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to SqUaRe48 Send a message via MSN to SqUaRe48
Default Problem..

Hi there!
I have problems getting data out of the db. Here's my code:

$db = mysql_connect("localhost", "root");
mysql_select_db("mydb",$db);
$result = mysql_query("SELECT * FROM employees",$db);

$varden = mysql_fetch_array($result,MYSQL_ASSOC)
?>
<?=$varden['first'];?>
<?=$varden['last'];?>
<?=$varden['address'];?>
<?=$varden['position'];?>
<?
mysql_close();
?>

It's telling me:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\inetpub\wwwroot\afab\hello.php on line 27

What have I done wrong?

Best regards,
Martin Johansson
+46 70 300 33 20
Squaremedia HB
[email protected]
 
Old June 26th, 2003, 05:30 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by SqUaRe48

What have I done wrong?
I'd guess it's because you haven't specified root's password in your connection. I dare say the database is refusing connection as a result, so none of the remaining work gets done. You really ought to use "or die()" at each stage of the connection operation, to output a message, should it fail.

Dan
 
Old July 5th, 2003, 07:44 PM
Registered User
 
Join Date: Jul 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

you must feed function 3 properties. if password is empty then use "".

 
Old July 7th, 2003, 02:27 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Daniel Walker
I'd guess it's because you haven't specified root's password in your connection. I dare say the database is refusing connection as a result, so none of the remaining work gets done. You really ought to use "or die()" at each stage of the connection operation, to output a message, should it fail.
This is a good approach for developing and testing your site, but I'd never use "or die(...)" in a live site. If there's a problem, it's much more user-friendly to redirect the user to some error page that says "We are experiencing problems with our database. The system administrator has been notified, please try your request again later."


Quote:
quote:Originally posted by jae_green
 you must feed function 3 properties. if password is empty then use "".
This is also technically incorrect, since the default value for the password param is the empty string (blank password). I'd be surprised if the first of the following function calls works and the other doesn't:

Code:
$conn = mysql_connect("localhost", "root")
            or die('no password failed');
$conn = mysql_connect("localhost", "root", "")
            or die('blank password failed');

Take care,

Nik
http://www.bigaction.org/
 
Old September 18th, 2003, 04:39 PM
Registered User
 
Join Date: Sep 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Just for added emphasis... even though the problem is old by now.. adding in the following helps in debugging when a script has multiple queries..

$sql8 = "select * from tbl"; //sql statement
$RS8 = MYSQL_QUERY($sql8) or die("Invalid query 8: " . mysql_error());

the mysql_error() is so very helpful

Rob












Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.