donglie1898 2017-11-25 16:15
浏览 53

如何在脱机服务器(Xampp)中链接基于HTML的网站中的数据库?

I have created a website for my versity project...But I am asked to add a database in it..That's why I need to know how to add a database via xamp in a website.

  • 写回答

1条回答 默认 最新

  • douling8087 2017-11-27 09:33
    关注

    Use this code to create a connection to your database from php

    <?php
    $servername = "localhost";
    $username = "root";
    $password ="db-password";
    $dbname = "db-name";
    
    //create connection
    $conn = new mysqli($servername,$username,$password,$dbname);
    //check connection
    if ($conn->connect_error) {
        die("connection failed" .$conn->$connect_error);
    }
    
    ?>
    

    use this link to understand how to create and execute queries.

    https://www.w3schools.com/php/php_mysql_connect.asp

    评论

报告相同问题?