doulan8054 2017-06-30 13:55
浏览 54
已采纳

用SQL和PHP连接到数据库[关闭]

I'm making a website that uses SQL and PHP functionalities. How do I connect to a database?

  • 写回答

3条回答 默认 最新

  • drh47606 2017-06-30 13:58
    关注

    The easiest way that I do with my site is make a file called db.php containing:

    <?php
    $host = 'localhost';
    $user = 'root';
    $pass = 'password';
    $db = 'databasename';
    $mysqli = new mysqli($host,$user,$pass,$db) or die($mysqli->error);
    

    ..then in the index.php file, at the top:

    <?php
    require_once('db.php')
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?