Results 1 to 15 of 15
  1. #1
    Join Date
    May 2011
    Posts
    6

    Database not connecting - Wamp Server

    Hi

    I got to develop my whole database in Wampserver 2.1 (it's the latest set). But now I cannot connect to MySQL through PHP in Wamp. I have searched a lot but still have no clue as to what is causing problems.

    No errors are being displayed. I have tried a number of code combination including "if(!)" and nothing has worked.

    CAN ANYONE HELP PLEASE.

    Here is the current code I am trying which returns blank page:

    <?php
    $dbhost = 'localhost';
    $dbuser = 'root';
    $dbpass = 'xyz';
    $db = 'scorecard';

    $conn = mysql_connect($dbhost,$dbuser,$dbpass);
    if (!$conn)
    die('Could not connect: ' . mysql_error());
    }
    echo 'Connected successfully';
    ?>

  2. #2
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    860
    You should check your php.ini settings. It might be the case that you are not reporting the errors. Alternatively you can force displaying the errors by adding this line into your code at the top:

    ini_set("display_errors",1);

    Here is the link to the explanation:

    PHP: Runtime Configuration - Manual
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com

  3. #3
    Join Date
    May 2011
    Posts
    6

    RE: php.ini not helping to report errors in Database Connection - Wamp

    Thanks Ronan for your reply.

    I have tried your suggestion but i still get blank page. No error messages are being displayed.

    Moreover, where does php.ini reside in Wamp directory?

    Now the code looks like this:

    <?php
    ini_set("display_errors",1);

    $dbhost = 'localhost:3360';
    $dbuser = 'root';
    $dbpass = '7years';
    $db = 'scorecard';

    $conn = mysql_connect($dbhost,$dbuser,$dbpass);

    if (!$conn)
    die('Could not connect: ' . mysql_error());
    }
    echo 'Connected successfully';
    ?>

    PLEASE HELP.

  4. #4
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    860
    The default port for MySQL is 3306 and not 3360 as you have put in. Perhaps this is the issue? Also if you have a firewall enabled make sure connections to 3306 are open.
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com

  5. #5
    Join Date
    May 2011
    Posts
    6

    Database not connecting - Port is also open - Wamp

    Thx Ronan for pointing out the error in port number.

    However, I have corrected the port number and have specifically opened the port as well but still blank page.

    Do you think it can have anything to do with MySQL? But then PHP must give error.

    Do you need MySQL log for any further details on that?

    Thanks again. Looking forward to more help.

  6. #6
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    860
    Can you log in to MySQL with the mysql command line application? Let's start there to see if the MySQL service is running.

    You are correct in so far as PHP should be returning some kind of error. But as there are so many components involved i.e. MySQL, MySQL client and PHP we need to try and logically work out where the problem lies.
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com

  7. #7
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    12,353
    consider changing
    PHP Code:
    ini_set("display_errors",1); 
    to
    PHP Code:
    Error_Reporting (E_ALL E_STRICT); 
    PHP: error_reporting - Manual

    consider changing the
    PHP Code:
    $conn mysql_connect($dbhost,$dbuser,$dbpass);

    if (!
    $conn
    die(
    'Could not connect: ' mysql_error());
    ... 
    to
    PHP Code:
    $conn mysql_connect($dbhost,$dbuser,$dbpass) or die('Could not connect: '.mysql_error());... 
    http://i792.photobucket.com/albums/y.../miniDGR-0.jpg I've taken part in the Distinguished Gentlemans ride, and although I enjoyed the day the main focus was to raise awareness of Prostrate Cancer and raise some funds for research. Many thanks to the many sponsors who helped me raise some 360 towards this cause, its much appreciated and rather humbling.

    http://www.gentlemansride.com/rider/healdem

  8. #8
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    12,353
    there may be an issue with the spaces before and aftere the concatenation of the could not connect
    Ive seen errors before when unable to establish a connection.
    http://i792.photobucket.com/albums/y.../miniDGR-0.jpg I've taken part in the Distinguished Gentlemans ride, and although I enjoyed the day the main focus was to raise awareness of Prostrate Cancer and raise some funds for research. Many thanks to the many sponsors who helped me raise some 360 towards this cause, its much appreciated and rather humbling.

    http://www.gentlemansride.com/rider/healdem

  9. #9
    Join Date
    May 2011
    Posts
    6

    Database not connecting - MySQL Console is OK - Wamp

    Dear Ronan

    MySQL Console is working fine. MySQL is running. Yet it doesn't connect with php.

    Do you have msn or skype id where we could talk abt it in detail in a go?

    Thanks for bearing with me.

  10. #10
    Join Date
    May 2008
    Posts
    277
    Quote Originally Posted by xuhaib View Post
    PHP Code:
    if (!$conn
        die(
    'Could not connect: ' mysql_error());

    This should be raising a syntax error, which would prevent the script from running at all. However, that should be displayed in your browser, unless you've totally disabled error reporting.

    This is correct:

    PHP Code:
    if (!$conn)
        die(
    'Could not connect: ' mysql_error()); 
    or:

    PHP Code:
    if (!$conn) {
        die(
    'Could not connect: ' mysql_error());


  11. #11
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    12,353
    it is a PHP you should be tracking down first
    until you have got a reliable error report you dont' knwo if this is PHP problem or MySQL problem
    the failure to report anything tell sme you don't have the error reporting correctly set up. PHP out of the box used to report any and all errors that changed IIRC PHP 5, so you know have to explicitly tell PHP to report errors.

    Theres things you can do to check if its MySQL though
    run a copy of MySQL Workbench and connect to the database, using the smae user id and password you are usign in your script. if the db server is on the same computer as the script runs on then consider connecting to the local host using the userid + password combo
    if its on another computer as the webserver this test doenst' prove anything as you may need to assign the permissions.

    consider running a PHP script
    PHP Code:
    <?PHP
    phpinfo
    ()
    ?>
    however get a PHP script that reports errors
    http://i792.photobucket.com/albums/y.../miniDGR-0.jpg I've taken part in the Distinguished Gentlemans ride, and although I enjoyed the day the main focus was to raise awareness of Prostrate Cancer and raise some funds for research. Many thanks to the many sponsors who helped me raise some 360 towards this cause, its much appreciated and rather humbling.

    http://www.gentlemansride.com/rider/healdem

  12. #12
    Join Date
    Nov 2012
    Posts
    2

    database not connecting - wamp sever

    ERROR is
    Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'SYSTEM'@'localhost' (using password: NO) in C:\wamp\www\ols\insert.php on line 2
    Could not connect: Access denied for user 'SYSTEM'@'localhost' (using password: NO)
    my code
    <?php
    $con = mysql_connect("","","");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
    $con = mysql_connect("","","");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
    mysql_select_db("osl", $con);
    mysql_query("INSERT INTO details (name, emailid, phno, pswd)
    VALUES (('$_POST[name]', '$_POST[emailid]', '$_POST[phno]', '$_POST[pswd]')");
    mysql_close($con);
    ?>
    plz reply soon

  13. #13
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    12,353
    what that error is telling you is that your server is up and running but you do not have permission to connect the specified user to the specified database
    it could be
    you have mistyped the user ID or password or database or some combination thereof
    you haven't GRANTed permissions for your user to that DB for that host
    whether you use the MySQL coimmand line client (such as MySQL.exe in windows) or a GUI client such as MySQL's own Workbench or HeidiSQL or similar is up to you
    http://i792.photobucket.com/albums/y.../miniDGR-0.jpg I've taken part in the Distinguished Gentlemans ride, and although I enjoyed the day the main focus was to raise awareness of Prostrate Cancer and raise some funds for research. Many thanks to the many sponsors who helped me raise some 360 towards this cause, its much appreciated and rather humbling.

    http://www.gentlemansride.com/rider/healdem

  14. #14
    Join Date
    Nov 2012
    Posts
    2
    i have checked the user name and password are crt. i guess the problem is sql and php are not getting connected. am using wammp server so r v suppose to install anythin else to get them connected.

  15. #15
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    12,353
    check the userid, password AND the computer or host(s) this user id is allowed to connect with
    Check the user (once authenticated) has access to the specified database

    as said before the error message is telling you that PHP CAN talk to the server but the server is rejecting the connection because of a permissions issue
    the error message is telling you that your code is not using a password when trying to establish the connection
    http://i792.photobucket.com/albums/y.../miniDGR-0.jpg I've taken part in the Distinguished Gentlemans ride, and although I enjoyed the day the main focus was to raise awareness of Prostrate Cancer and raise some funds for research. Many thanks to the many sponsors who helped me raise some 360 towards this cause, its much appreciated and rather humbling.

    http://www.gentlemansride.com/rider/healdem

Posting Permissions

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