I know this type of question has been asked a million times before, but I haven't been able to find the right answer for me. My situation is as follows:
I click a button and after that I call both a mysqli SELECT and INSERT function from my database class. The SELECT function is executed perfectly, but right after that I get the fatal error you can see in the title.
This is the line I'm trying to execute:
insertPrefixes($dbAddress, $netmask, $prefixName, $nrOfHosts, getParentID($longest));
The function itself:
function insertPrefixes($dbAddress, $netmask, $prefixName, $nrOfHosts, $prefixParent = 0) {
$db = new db();
/* Prepare data to be inserted */
$table = "prefix";
if($prefixParent < 1) {
$data = array("pfx_prefix" => $dbAddress,
"pfx_length" => $netmask,
"pfx_version" => 4,
"pfx_name" => $prefixName,
"pfx_capacity" => $nrOfHosts);
$typeDef = array("i", "i", "i", "s", "i");
} else {
$data = array("pfx_prefix" => $dbAddress,
"pfx_length" => $netmask,
"pfx_version" => 4,
"pfx_name" => $prefixName,
"pfx_capacity" => $nrOfHosts,
"" => $prefixParent);
$typeDef = array("i", "i", "i", "s", "i", "i");
}
/* Insert the data into the database */
$db->sql_insert($data, $typeDef, $table);
$db->disconnect();
}
The line where it goes wrong (in database.class.php) in the 'sql_insert' function:
/* Prepare statement */
$stmt = $this->connect()->stmt_init();
if ($stmt->prepare($sql)) {
// statement code
}
Both my SELECT and INSERT functions work perfectly on their own, but once I call both the function in the same run, I always get the 'Call to a member function stmt_init() on a non-object' error. Is there something I am forgetting? If you need more code please ask :)