Connecting to MySQL database

Discussion in 'Free Hosting' started by NaK, Nov 12, 2017.

  1. NaK

    NaK New Member

    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
    I uploaded my website but it doesn't work correctly. It uses a database, which I created, but my pages can't connect to the database. I have the database name, the user name and password and am using localhost as the host. Is there a different host definition?
     
  2. lylex10h

    lylex10h Member

    Messages:
    404
    Likes Received:
    20
    Trophy Points:
    18
    Last edited: Nov 13, 2017
  3. NaK

    NaK New Member

    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
    I checked everything, including the database password and it seems to be OK.
    Which username do you need? for the account or the database?
    The account is yolk100@gmx.com
    The database is gsnevada_admin
     
  4. lylex10h

    lylex10h Member

    Messages:
    404
    Likes Received:
    20
    Trophy Points:
    18
    What is the user name in your database connection string and what is the connection error?
     
  5. NaK

    NaK New Member

    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
    The database connection user name is gsnevada_admin. The password is !qazxsw@
    I get a simple message (generated by the sql connector): Unable to connect.
     
  6. lylex10h

    lylex10h Member

    Messages:
    404
    Likes Received:
    20
    Trophy Points:
    18
    Does the database user have all the permissions?
    cPanel --> MySQL Databases --> Click on "gsnevada_admin" below Privileged Users.
     
  7. NaK

    NaK New Member

    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
  8. lylex10h

    lylex10h Member

    Messages:
    404
    Likes Received:
    20
    Trophy Points:
    18
    Is the user assigned to the database and can you access the database with phpMyAdmin?
     
  9. NaK

    NaK New Member

    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
    Yes to both. I used NetObjects Fusion 12 to create the website and am now suspicious that the problem is with their database connector. When I try connecting with my own php mysql statement it seems to connect fine. I will look into this later and report.
     
  10. NaK

    NaK New Member

    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
    What is the host for the database? I used "localhost" but if it's different it would explain the trouble I'm having connecting.
     
  11. lylex10h

    lylex10h Member

    Messages:
    404
    Likes Received:
    20
    Trophy Points:
    18
    This is the code in my wp-config.php file (database, user and password changed)

    PHP:
    // ** MySQL settings - You can get this info from your web host ** //
    /** The name of the database for WordPress */
    define('DB_NAME''my_database');

    /** MySQL database username */
    define('DB_USER''my_user');

    /** MySQL database password */
    define('DB_PASSWORD''my_p@$$W0rd');

    /** MySQL hostname */
    define('DB_HOST''localhost');
     
  12. NaK

    NaK New Member

    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
    It still can't connect. I checked the PHP MySql syntax and everything seems to be OK. The same script works on three other hosts. There muct be something strange in the PHP configuration.
     
  13. lylex10h

    lylex10h Member

    Messages:
    404
    Likes Received:
    20
    Trophy Points:
    18
    I used the following test script and it worked:

    PHP:
    <?php
    # Fill our vars and run on cli
    # $ php -f db-connect-test.php
    $dbname 'name';
    $dbuser 'user';
    $dbpass 'pass';
    $dbhost 'localhost';
    $link mysqli_connect($dbhost$dbuser$dbpass) or die("Unable to Connect to '$dbhost'");
    mysqli_select_db($link$dbname) or die("Could not open the db '$dbname'");
    $test_query "SHOW TABLES FROM $dbname";
    $result mysqli_query($link$test_query);
    $tblCnt 0;
    while(
    $tbl mysqli_fetch_array($result)) {
      
    $tblCnt++;
      
    #echo $tbl[0]."<br />\n";
    }
    if (!
    $tblCnt) {
      echo 
    "There are no tables<br />\n";
    } else {
      echo 
    "There are $tblCnt tables<br />\n";
    }
    From https://gist.github.com/M165437/421cd2d23e53a111541a483971f7368b
     
  14. NaK

    NaK New Member

    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
    I'm using php 5.6:
    mysql_connect("localhost", "admin", "password") or die('Error connecting to mysql');
    mysql_select_db("databse_name") or die(mysql_error());
     
  15. lylex10h

    lylex10h Member

    Messages:
    404
    Likes Received:
    20
    Trophy Points:
    18
    I use PHP 7 so that's probably it. Good luck.
     
  16. Anna

    Anna I am just me Staff Member

    Messages:
    8,254
    Likes Received:
    222
    Trophy Points:
    63
    You might want to switch over to mysqli or PDO for your connection, don't know by heart when it was removed but using mysql_xxx has been depreceted for a while. Simplest is to switch to mysqli_xxx, for most statements it is as easy as just changing mysql_connect to mysqli_connect etc. Some have minor syntax changes, such as mysql_connect() now takes four parameters, where the last one lets you select the database right away instead of using mysql_select_db() after the connection has been set up (you can still use that with mysqli as well though). I know there's a few more syntax changes too, but I haven't really had much reason to look them up.
     
  17. caftpx10

    caftpx10 Well-Known Member

    Messages:
    1,473
    Likes Received:
    104
    Trophy Points:
    63
    ext/mysql was removed in PHP 7.0.
     

Share This Page