Results 1 to 3 of 3

Thread: How to use the php function mysqli_connect() to work with phpMyAdmin databases.

  1. #1
    Join Date
    Jun 2008
    Location
    Pacific Northwest
    Posts
    374

    Default How to use the php function mysqli_connect() to work with phpMyAdmin databases.

    I am a newbie to php and databases.
    I followed the openSuSE LAMP guide. I installed the mariadb and phpMyAdmin . I opened a port in the firewall for a mysql database server.

    In a browser (Chromium):
    localhost/index.htm displays "It works"
    localhost/phpinfo.php displays PHP version 7.0.7. The section for mysqli is present.
    localhost/phpMyAdmin pulls up phpMyAdmin

    I created a new database, created several tables and several relationships.

    I created the file connectPHP.php:
    <?php
    //Step1
    $localhost = 'localhost';
    $username = 'root';
    $password = 'password';
    $database_name = 'databaseName';
    $db = mysqli_connect($localhost,$username,$password,$database_name)
    or die('Error connecting to MySQL server.');
    ?>
    -- where password is the password used to get into phpMyAdmin, databaseName is the name of the database I created.

    I placed this in /home/myName/public_html
    localhost/~myName/connectPHP.php -- gives the die message

    I opened a terminal console with root privileges and copied the file into /srv/www/htdocs
    localhost/connectPHP.php - also gives the die message

    Any ideas? I think I am very close.
    Thank you in advance
    The greatest obstacle to discovery is not ignorance, it is the illusion of knowledge.
    Daniel J. Boorstin US Patent Office

  2. #2
    Join Date
    Jun 2008
    Location
    Groningen, Netherlands
    Posts
    20,316
    Blog Entries
    14

    Default Re: How to use the php function mysqli_connect() to work with phpMyAdmin databases.

    This comes from one of the sites I administer:
    Code:
    <?php
    $servername = "localhost";
    $username = "username";
    $password = "password";
    
    
    // Create connection
    $conn = new mysqli($servername, $username, $password);
    
    
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    } 
    echo "Connected successfully";
    ?>
    Adjust to your needs and it should work.
    ° Appreciate my reply? Click the star and let me know why.

    ° Perfection is not gonna happen. No way.

    http://en.opensuse.org/User:Knurpht
    http://nl.opensuse.org/Gebruiker:Knurpht

  3. #3
    Join Date
    Jun 2008
    Location
    Pacific Northwest
    Posts
    374

    Default Re: How to use the php function mysqli_connect() to work with phpMyAdmin databases.

    Thank you. This code worked. (Note: file is located in /srv/www/htdocs)
    The greatest obstacle to discovery is not ignorance, it is the illusion of knowledge.
    Daniel J. Boorstin US Patent Office

Posting Permissions

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