I have code with the following form:
<?php
function doSomething{
$con->tralalala();
}
$con = connectToDatabase;
doSomething();
?>
This (type) code does not work because doSomething () does not have a database connection. Can someone explain why not? I am creating a $ con connection before I call doSomething (). So why does a function act as if there is no connection?
Is there any way to fix this, except for passing the connection to a function like doSomething ($ con)?
source
share