I'm having trouble with an MySQLi query and i cannot fint out the cause for it.
When executing the query itsself (with phpmyadmin) it runs just fine. Allso when executing it with php it throws no errors. see below for details.
There have been allot of other posts about this on SO but none of them fixes my issue. While i'm aware this will probably a stupid mistake i'm overlooking, this is a bit time sensitive so all support is welcome.
Code wich populated array wich will be fed to the function
....
//Prepare DB Data
$NewNodesData = array();
foreach($NewNodes as $NewNode){
//Actual Data
$NewNodesData[$NewNode['Node_Name']]['Node_Name'] = $NewNode['Node_Name'] ;
$NewNodesData[$NewNode['Node_Name']]['Platform'] = $NewNode['Platform'] ;
$NewNodesData[$NewNode['Node_Name']]['Policy_Domain'] = $NewNode['Policy_Domain'] ;
$NewNodesData[$NewNode['Node_Name']]['ProxyNode_target'] = $NewNode['ProxyNode_target'] ;
$NewNodesData[$NewNode['Node_Name']]['ProxyNode_Agent'] = $NewNode['ProxyNode_Agent'] ;
//Set empty fields(will be polulated later)
$NewNodesData[$NewNode['Node_Name']]['server_name'] = NULL ;
$NewNodesData[$NewNode['Node_Name']]['unique_ident'] = NULL ;
$NewNodesData[$NewNode['Node_Name']]['exp_suc'] = NULL ;
$NewNodesData[$NewNode['Node_Name']]['active'] = 1 ;
$NewNodesData[$NewNode['Node_Name']]['kostenplaats'] = NULL ;
$NewNodesData[$NewNode['Node_Name']]['contact'] = NULL ;
$NewNodesData[$NewNode['Node_Name']]['schedule'] = NULL ;
$NewNodesData[$NewNode['Node_Name']]['filespace_name'] = NULL ;
$NewNodesData[$NewNode['Node_Name']]['fsid'] = NULL ;
$NewNodesData[$NewNode['Node_Name']]['mgmtclass'] = NULL ;
$NewNodesData[$NewNode['Node_Name']]['script'] = NULL ;
$NewNodesData[$NewNode['Node_Name']]['comment'] = NULL ;
$NewNodesData[$NewNode['Node_Name']]['node_data'] = NULL ;
$NewNodesData[$NewNode['Node_Name']]['host_node'] = NULL ;
$NewNodesData[$NewNode['Node_Name']]['editedby'] = "Auto Import Script" ;
$NewNodesData[$NewNode['Node_Name']]['editedts'] = time() ;
$NewNodesData[$NewNode['Node_Name']]['fsid_tsm2'] = NULL ;
}
//Save new nodes to DB
foreach($NewNodesData as $NewNodeData){
$user_name = "Auto Import Script";
echo CreateTDPNode($NewNodeData);
}
Function wich executes DB query:
function CreateTDPNode($nodedata){
global $mysqli;
global $user_name;
foreach($nodedata as $key => $data){
if(is_numeric($data) AND $key != "kostenplaats"){
$data = intval($data);
}
if($data == ""){
$data = NULL;
}
${$key} = $data;
}
$editedby = $user_name;
$editedts = time();
if ($stmt = $mysqli->prepare("INSERT INTO tdp_nodes ( server_name, Node_Name, unique_ident, exp_suc, active, kostenplaats, contact, sched, filespace_name, fsid, mgmtclass, script, Platform, com, node_data, editedby, editedts, fsid_tsm2, Policy_Domain ) VALUES ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )")) {
$stmt->bind_param("sssiiisssissssssiis", $nodename, $nodename, $unid, $exp_suc, $active, $kostenplaats, $contact, $schedule, $filespace_name, $fsid, $mgmtclass, $script, $Platform, $comment, $storage, $editedby, $editedts, $fsid_tsm2, $Policy_Domain);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
$result = "<font color=\"green\">Node Toegevoegd </font><br>";
// var_dump($stmt);
}
else{
$result = "Errors:" . $mysqli->error . "<br>";
}
return $result;
}
The mysqli_stmt has all null values, i dont know the cause of this, but allso, no errors:
object(mysqli_stmt)[2]
public 'affected_rows' => null
public 'insert_id' => null
public 'num_rows' => null
public 'param_count' => null
public 'field_count' => null
public 'errno' => null
public 'error' => null
public 'error_list' => null
public 'sqlstate' => null
public 'id' => null
Any tips are appreciated!