Hi,
I have a stored procedure where I insert and fetch LAST_INSERT_ID() in a select statement and I am able to call the procedure both in PHPMyAdmin and PHP script without any problem. Unfortunately, if I use the PHP script the insertion does not persists in the table whereas with PHPMyAdmin it does.
Is anything wrong with the script?
public function call($procedure, $in = null){
$link = $this->connect();
$call_sql = "call $procedure(";
$is_in_set = isset($in);
try{
$link->begin_transaction();
if($is_in_set){
$set_sql = 'SET ';
$types = '';
$length = sizeof($in);
for($i = 0; $i < $length; $i++){
$variable = "@in$i";
$call_sql .= "$variable, ";
$set_sql .= "$variable := ?, ";
$types .= $this->typeSelector($in[$i]);
}
$call_sql = rtrim($call_sql,', ');
$set_sql = rtrim($set_sql,', ');
array_unshift($in, $types);
$stmt = $link->prepare($set_sql);
$stmtReflection = new ReflectionClass('mysqli_stmt');
$reflectionMethod = $stmtReflection->getMethod('bind_param');
$reflectionMethod->invokeArgs($stmt, $in);
$stmt->execute();
$stmt->close();
}
$call_sql .= ')';
$stmt = $link->query($call_sql);
$link->commit();
$result = $stmt->fetch_all(MYSQLI_ASSOC);
$stmt->close();
return $result;
}catch(Exception $e){
$link->rollback();
die("(" . $e->getCode() . ") " . $e->getMessage());
}
}