SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
-
Jun 20, 2002, 08:04 #1
- Join Date
- Jan 2002
- Location
- Norrkoping, SWEDEN
- Posts
- 88
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Error when testing MySQL installation
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\Inetpub\wwwroot\server_test.php on line 5
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Inetpub\wwwroot\server_test.php on line 6PHP Code:<?
$sql="SELECT count(user) FROM user";
$conn=mysql_connect("192.168.0.116", "root", "");
mysql_select_db("mysql");
$result=mysql_query($conn,$sql);
$siffra=mysql_num_rows($result);
echo $siffra;
?>
The "funny" part is that when my fried tries this on his MySQL server, it works!
I've installed PHP and MySQL on an Win 2000 Advanced Server.
Help, please!David Andersson Davve
-MSc in Media Technology and Engineering:
Working at AdLibris
-
Jun 20, 2002, 08:20 #2
- Join Date
- Jun 2002
- Location
- .chicago.il.us
- Posts
- 957
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I believe your problem is in the syntax of your mysql_query() command, in which the SQL statement should come first, and the connection is second.
you should test the results of each step... never count on it all working.
Plus, this is far easier to debug...
PHP Code:<?php
$sql="SELECT count(user) FROM user";
if($conn=mysql_connect("192.168.0.116", "root", "")){
if(!mysql_select_db("mysql", $conn)){
mysql_close($conn);
die ("unable to select database");
}
if($result=mysql_query($sql,$conn)){
$siffra=mysql_num_rows($result);
echo $siffra;
}
mysql_close($conn);
}else{
die ("unable to connect to mysql");
}
?>Last edited by randem; Jun 20, 2002 at 08:23.
-
Jun 20, 2002, 08:31 #3
- Join Date
- Jan 2002
- Location
- Norrkoping, SWEDEN
- Posts
- 88
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Good thinking! But, I still get the errors, only this time I get only one of them!
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\Inetpub\wwwroot\server_test.php on line 8PHP Code:<?php
$sql="SELECT count(user) FROM user";
if($conn=mysql_connect("192.168.0.116", "root", "")){
if(!mysql_select_db("mysql", $conn)){
mysql_close($conn);
die ("unable to select database");
}
if($result=mysql_query($conn,$sql)){
$siffra=mysql_num_rows($result);
echo $siffra;
}
mysql_close($conn);
}else{
die ("unable to connect to mysql");
}
?>
Maybe this is why? MySQL-Link sounds like something like that...David Andersson Davve
-MSc in Media Technology and Engineering:
Working at AdLibris
-
Jun 20, 2002, 08:34 #4
- Join Date
- Jun 2002
- Location
- .chicago.il.us
- Posts
- 957
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
you still have your $conn and $sql arguments backwards in the mysql_query() command.
re-read my previous reply
-
Jun 20, 2002, 08:56 #5
- Join Date
- Jan 2002
- Location
- Norrkoping, SWEDEN
- Posts
- 88
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I'm really sorry... Thanks! It's working now.David Andersson Davve
-MSc in Media Technology and Engineering:
Working at AdLibris
Bookmarks