Results 1 to 4 of 4

Thread: Installing PHP

  1. #1
    Join Date
    Aug 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Installing PHP

    Hi guys,

    I am somewhat competent with HTML, CSS and Javascript, now I'm trying to start using PHP. I've downloaded and installed Apache, PHP and MySQL and they kind of work. I can use MySQL on its own fine, and PHP on its own fine (I can run phpinfo, echo Hello World etc. and can visit pages on localhost). However I can't get my PHP script to work using MySQL. I copied out *exactly* a script from O'Reilly's PHP and get the following errors printed out:

    Warning: mysql_connect() [function.mysql-connect]: [2002] A connection attempt failed because the connected party did not (trying to connect via tcp://localhost:3306) in C:\AppServ\www\mysql2.php on line 14

    Warning: mysql_connect() [function.mysql-connect]: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\AppServ\www\mysql2.php on line 14
    2002
    Warning: mysql_select_db() [function.mysql-select-db]: [2002] A connection attempt failed because the connected party did not (trying to connect via tcp://localhost:3306) in C:\AppServ\www\mysql2.php on line 21

    Warning: mysql_select_db() [function.mysql-select-db]: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\AppServ\www\mysql2.php on line 21

    Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in C:\AppServ\www\mysql2.php on line 21

    Fatal error: Maximum execution time of 60 seconds exceeded in C:\AppServ\www\mysql2.php on line 21

    Here is the script, the password, host etc. is definitely correct, I've double checked in MySQL itself.

    PHP Code:
    <html>
    <head>
    <basefont face="Arial">
    </head>
    <body>

    <?php
    $host 
    "localhost";
    $user "root";
    $pass "elephant";
    $db "favourite_foods";

    // open connection
    $connection mysql_connect($host$user$pass); /*THIS IS LINE 14!!!!*/

    if(mysql_error()) {
    echo 
    mysql_errno();
    }

    // select database
    mysql_select_db($db) or die ("Unable to select database!"); /*THIS IS LINE 21!!!!*/


    // create query
    $query "SELECT * FROM favourite_food";

    // execute query
    $result mysql_query($query) or die ("Error in query: $query. ".mysql_error());

    // see if any rows were returned
    if (mysql_num_rows($result)>0) {
    // yes
    // print them one after another
    echo "<table cellpadding=10 border=1>";
    while(
    $row mysql_fetch_row($result)) {
    echo 
    "<tr>";
    echo 
    "<td>".$row[0]."</td>";
    echo 
    "<td>" $row[1]."</td>";
    echo 
    "<td>".$row[2]."</td>";
    echo 
    "</tr>";
    }
    echo 
    "</table>";
    }
    else {
    // no
    // print status message
    echo "No rows found!";
    }

    // free result set memory
    mysql_free_result($result);

    // close connection
    mysql_close($connection);

    ?>

    </body>
    </html>
    Is there anything obvious I'm doing wrong? Any help would be very much appreciated. Thanks, Bob
    Last edited by Snookerman; 08-06-2009 at 12:17 PM.

  2. #2
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Definitely nothing wrong with the way the script connects, normally if the user / password is incorrect the mysql error will say "Access denied for user $user"

    So it's probably to do with how you've placed the files, have you googled your error message for more information?

  3. #3
    Join Date
    Oct 2008
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    you need to copy this 2 files in your c:\windows\system32

    libmysql.dll and libeay32.dll coming from your php dll files.

  4. #4
    Join Date
    Feb 2009
    Posts
    73
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    just install xampp, it's more easier.

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
  •