ben ben - 1 year ago 58
MySQL Question

Connecting my website to MySql database

The hosting site that I am using to host my website automatically links you phpmyadmin and MySql. What code do I need to connect to my specific database so that within my webpages I can edit the table?

ben ben
Answer Source


            // Log into server
            $servername = "localhost";
            $username = "username";
            $password = "password";
            $dbname = "data base name";

            // Create connection
            $conn = mysqli_connect($servername, $username, $password, $dbname);
            // Check connection
            if (!$conn) {
                die("Connection failed: " . mysqli_connect_error());

            // truncate table
            $sql = "sql command here";
            $result = mysqli_query($conn, $sql);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download