PHP - mysqli函数

At the moment I use the mysql_connect, mysql_select_db, mysql_query functions from PHP. I have a file with mysql_connect so I can require this file in all other PHP files and I have in every file a connection to MySQL.

Now i have to change it to mysqli_connect. The problem now: I have for all query to set a connection? why? after one query the Connection will be closed. So I have to set a new mysqli_connection.

Is this ok, or what do I have to do that I need only one connection?

Connection.php

  $connect = mysqli_connect("test","test","test","test");

other php-file:

require("./Connection.php");

$result= mysqli_query($connect,"select portfolioview_id,portfolioview_text,portfolioview_longtext from portfolioview order by portfolioview_id desc");
while ($zeile = mysqli_fetch_array($connect,MYSQLI_ASSOC)):
    echo "test";                            

endwhile;

After this query, so when i start an second query i get the message:

Warning: mysqli_query() expects parameter 1 to be mysqli, resource given in C:\xampp\htdocs\limitless\connect_to_mysql.php on line 17

When i add a new Connection like in Connection.php it works.

You should consider using the object based method for queries then. It doesn't require changing argument order and this syntax should be repeatable

$res = $mysqli->query($sql);

You can still use this with the procedural functions

while($row = mysqli_fetch_assoc($res))