Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variable from different file in function without using global

Tags:

php

Ay,

I defined (in config.php):

$mysql = mysqli_connect (..);

for connecting to the mySQL database. now I want to use the variable in my functions (functions.php):

function x () { $fetch = ($mysql, "SELECT ...")); }

without using global:

function x () { global $mysql ... }

any clean ideas (procedural)?

like image 472
j0hn Avatar asked Sep 20 '26 23:09

j0hn


1 Answers

You can e.g. pass the connection resource to your function

function x ($mysqli) { $mysqli->... }
like image 178
VolkerK Avatar answered Sep 22 '26 12:09

VolkerK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!