Accessing a variable in a function from the main script
G'day all!
Say I've got this function that connects to the mysql database -
PHP Code:
function sqli_connect($username, $password) {
$connection = mysqli_connect("localhost", $username, $password);
//Test connection to database
if(mysqli_connect_errno()) {
echo "Installation error: Could not connect to database.";
exit;
}
}
Then I call it from here -
Code:
<?php
sqli_connect('****', '****');
//Create the databases
if(mysqli_query($connection,"CREATE DATABASE my_db")) { //Executes mysqli query and tests for a return of true at the same time
echo "Database my_db created successfully";
} else {
echo "Error creating database: " . mysqli_error($con);
}
?>
How can I give it the connection variable from the function?
Thanks all :)
keebs