I am trying to create a mysql table using php
I have the following function to create the table
class dbActions{
public $connection;
function dbConnect(){
$dbname = 'kilimokenya';
$dbhost = 'localhost';
$dbpass = '';
$dbuser = 'root';
$connection = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
if($connection ->connect_errno) echo ($connection ->connect_error());
}
function createCustomerTbl(){
GLOBAL $connection;
$CustomerTbl = "CREATE TABLE customers_tbl(
customer_id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
emailAddress VARCHAR(30) NOT NULL,
phone_number VARCHAR(15) NOT NULL,
dateRegistered TIMESTAMP
)";
$check = $connection ->query($CustomerTbl);
if(!$check)
echo "Customer table not created because ".$connection ->error;
return true;
}
I call the function here :
$dbObject = new dbActions();
$dbObject ->dbconnect();
$dbObject ->createCustomerTbl();
I get the following error when i run the code: Fatal error: Call to a member function query() on null in C:\xampp\htdocs\current\kilimokenyafoods\common\server.php on line 31
What im i missing?