Pass variable between PHP files

Asked

Viewed 29 times

0

That may be a duplicate question, but I have this problem. I took a project to continue the service here and it uses old functions like mysql_connect, mysql_querry and I need to change it. ex:

mysql_connect("localhost", "root", "",) or die ("Falha ao conectar ao banco de dados - ".mysql_error());

And it used a file with a function to make a connection to the database, and mysql_query did not need to pass a connection as parameter so it worked, since mysqli_query needs a connection, then every time I am using I have to open a new connection and then close at the end of mysqli_query.

Finally I wanted to know how to keep this connection file and send this variable $con to all the files you need. example:

$con = mysqli_connect("localhost", "root", "","db") or die ("Falha ao conectar ao banco de dados - ".mysqli_error($con));
  • Tried to give a include/require?

  • I had tested yes, but the first one always worked and the others didn’t, I was closing the connection. It’s normal to think about the error only hours later. Anyway, thank you very much

  • mysqli_query not necessarily requires connection pass.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.