SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast Davve's Avatar
    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 6
    PHP 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

  2. #2
    morphine for a wooden leg randem's Avatar
    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.

  3. #3
    SitePoint Enthusiast Davve's Avatar
    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 8
    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($conn,$sql)){
            
    $siffra=mysql_num_rows($result);
            echo 
    $siffra;
        }
        
    mysql_close($conn);
    }else{
        die (
    "unable to connect to mysql");
    }
    ?>
    But! I just remembered something. When I installed MySQL using Kevin Yank's tutorial, he was talking about renaming a .fnc file or something. The thing is that I never found the file that was to be renamed! So I never renamed and moved it.

    Maybe this is why? MySQL-Link sounds like something like that...
    David Andersson Davve
    -MSc in Media Technology and Engineering:
    Working at AdLibris

  4. #4
    morphine for a wooden leg randem's Avatar
    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

  5. #5
    SitePoint Enthusiast Davve's Avatar
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •