1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved How to create a connection to a MySQL database?

Discussion in 'Development' started by Minetron26, Jun 27, 2019.

  1. Minetron26

    Minetron26 Witch

    Messages:
    55
    GitHub:
    minetron26
    Hello, I was doing some tests, I was trying to make a connection to a MySQL database, but, there were only errors, I tried it as I would normally, but it did not work, in any of the ways.
    Does anyone have an idea of how to do it? Give me an example, or tell me how to do it.
     
  2. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    And we will reply with the normal method.
    Code doesn't work magically as you copy them. Show the error.
     
    Minetron26 likes this.
  3. KingOfTurkey38

    KingOfTurkey38 Spider

    Messages:
    7
    PHP:
     $this->db = new \mysqli("host""username""password""database name"port);
                 
    $this->db->query(
                           
    "CREATE TABLE IF NOT EXISTS PlayerBase(
                            username VARCHAR(20) PRIMARY KEY,
                            rank VARCHAR(20) DEFAULT 'Player');
                      "
    );
    just a example
     
    Minetron26 likes this.
  4. Destroyer57

    Destroyer57 Zombie

    Messages:
    275
    <?php
    $servername = "localip";
    $username = "username";
    $password = "pass";

    $conn = new mysqli($servername, $username, $password);

    if ($conn->connect_error) {
    die("Connection fail: " . $conn->connect_error);
    }
    echo "Connected successfully";
    ?>
     
    Minetron26 likes this.
  5. Minetron26

    Minetron26 Witch

    Messages:
    55
    GitHub:
    minetron26
    You are right, there should have been more details.
    The error that appears is that the "mysqli" class can not be found.
     
  6. Minetron26

    Minetron26 Witch

    Messages:
    55
    GitHub:
    minetron26
    As I said in the response to SOFe, the error says that the mysqli class can not be found.
     
  7. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Edit your bin\php\php.ini, delete the ; before the line with "extension=mysqli"
     
    Minetron26 likes this.
  8. Minetron26

    Minetron26 Witch

    Messages:
    55
    GitHub:
    minetron26
    Thanks you.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.