How to define mysqli connection in one php file and then use it on another file?

后端 未结 1 1115
臣服心动
臣服心动 2021-01-16 06:40

I am new to PHP and I`m using eclipse SDE to build a simple web application.

My Scenario is:

  1. I have index.php page that include the lo
相关标签:
1条回答
  • 2021-01-16 06:55

    Make file connection.php with all that have tangence with mysql connection and after ad in each file where you use mysql query the line include_once('connection.php'); or you can have include_once('some_folder\connection.php');

    If you are beginner you can use this mode to connect to DB

    mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
    $link = mysqli_connect('localhost', 'mysql_user', 'mysql_password');
    echo 'Connected successfully';
    
    $res = mysqli_query($link, "CREATE TEMPORARY TABLE myCity LIKE City");
    

    http://php.net/manual/en/mysqli.query.php

    0 讨论(0)
提交回复
热议问题