Results 1 to 2 of 2

Thread: mysql connection failed

  1. #1
    Registered
    Join Date
    Apr 2016
    Location
    Ontario
    Posts
    2
    Rep Power
    0

    mysql connection failed

    Help.

    I am doing a very standard sql connection using php5.6. here is my php code:

    <?php
    //$link = mysqli_connect('*mysql_server', '*username', '*password');

    if (!$link) {
    die('Could not connect: ' . mysqli_error());
    }
    echo 'Connected successfully';
    mysqli_select_db(*my_db);
    ?>

    I replaced all mysql with mysqli since it showed mysql is deprecated on my first try.

    I keep getting this error: mysqli_connect(): (HY000/2002): 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.

    thank you!!

  2. #2

    Join Date
    Sep 2002
    Location
    Auckland
    Posts
    1,356
    Rep Power
    17
    Quote Originally Posted by Jef View Post
    Help.

    I am doing a very standard sql connection using php5.6. here is my php code:

    <?php
    //$link = mysqli_connect('*mysql_server', '*username', '*password');
    Youve got the connection part as a quote/text - // - It wont process that line.

    take those quote lines out (not sure if thats the exact / proper phrase).

    Assuming you know that, here is my code for connecting to the database

    $mysqli = new mysqli("USER.powwebmysql.com", "DATABASE", "PASSWORD", "TABLE");

    if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    $GLOBALS['LOG'] .= "Connect failed: %s\n". mysqli_connect_error()."\n";
    exit();
    }
    USER - Your username

    DATABASE - database name

    PASSWORD / TABLE (obvious).


    I hope that helps

    PS - you can take out the GLOBALS part (ive got a variable to log various aspects of my scripts).

Tags for this Thread

Posting Permissions

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