|
Subject:
|
Problem..
|
|
Posted By:
|
SqUaRe48
|
Post Date:
|
6/18/2003 12:48:26 PM
|
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 martin@cdos.org
|
|
Reply By:
|
Daniel Walker
|
Reply Date:
|
6/26/2003 5:30:25 AM
|
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
|
|
Reply By:
|
jae_green
|
Reply Date:
|
7/5/2003 7:44:39 PM
|
you must feed function 3 properties. if password is empty then use "".
|
|
Reply By:
|
nikolai
|
Reply Date:
|
7/7/2003 2:27:40 PM
|
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: 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:
$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/
|
|
Reply By:
|
rob.weaver
|
Reply Date:
|
9/18/2003 4:39:12 PM
|
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
|