How can I avoid using global to access a variable inside a php function. I know I can store them as constants, but my variables contain sql and are many. Like this...
$selectSql = 'select name from table where name = :thisName' and year = :thisYear;
$selectSqlBind = array(":thisName" => $thisName,":thisYear" => $thisYear);
Here's how I currently do it
function myFunction (){
global $selectSql;
global $selectSqlBind;
$addUser = $conn->prepare($selectSql);
$addUser->execute($selectSqlBind);
//Other Stuff goes on
}
I also can do
function myFunction ($selectSql,$selectSqlBind){
$addUser = $conn->prepare($selectSql);
$addUser->execute($selectSqlBind);
//Other Stuff goes on
}
but how can I do
function myFunction (){
$addUser = $conn->prepare($selectSql);
$addUser->execute($selectSqlBind);
//Other Stuff goes on
}