1,新建conn.inc.php文件:
定义数据库连接常量如下:
<?php define("HOST",'localhost'); define("USER",'root'); define("PWD",'root'); define("DBNAME",'onecms');
2,新建mysqli.php文件:
<?php include 'conn.inc.php'; $mysqli=new mysqli(HOST,USER,PWD,DBNAME); if($mysqli->connect_errno){ die('数据库链接出错'.$mysqli->connect_error); }
下次连接数据库操作只需要引进mysqli.php文件即可
下一节