I have the following code :
try
{
if(!($stmt = $conn["DB"]->prepare('CALL `central`.`permissions_edit`(?,?,?,?,?);')))
{
$rtn["Errors"][] = "permissions_edit Prepare failed: (" . $conn["DB"]->errno . ") " . $conn["DB"]->error;
}
else{
foreach ($data as $user => $areas) {
foreach ($areas as $area => $access) {
foreach ($access as $acc => $active) {
if($active != "U")
{
if(!($stmt->bind_param(
'siiis',
$key,
$user,
$area,
$acc,
$active
)))
{
$rtn["Error"][] = "permissions_edit Bind failed: (" . $conn["DB"]->errno . ") " . $conn["DB"]->error;
}
else if(!($stmt->execute()))
{
$rtn["Errors"][] = "permissions_edit Execute failed: (" . $conn["DB"]->errno . ") " . $conn["DB"]->error;
}
else if($res = $stmt->get_result())
{
if ($row = $res->fetch_assoc())
{
if(isset($row["Success"]) && $row["Success"] )
{
$rtn["Results"][]= "user=$user areas=$area access=$acc active=$active Message=" . $row["Msg"];
}
else
{
$rtn["Success"] = false;
$rtn["Errors"][]= "user=$user areas=$area access=$acc active=$active Message=" . $row["Msg"];
}
}
}
else
{
$rtn["Errors"][] = "permissions_edit Get failed: (" . $conn["DB"]->errno . ") " . $conn["DB"]->error;
}
}
else
$rtn["Results"][]= "user=$user areas=$area access=$acc active=$active Message=Unchanged";
}
}
}
}
}
catch(Exception $e)
{
$rtn["Errors"][] = "permissions_edit Error(" . $conn["DB"]->errno . "): " . $conn["DB"]->error;
}
using this code where the loop repeats 1-2 times works perfectly however using this code where the loop repeats more than twice causes the POST to PHP to terminated with no Response
and generates the following in the MySql log,
2017-03-03T16:47:49.284972Z 450 [Note] Aborted connection 450 to db: 'central' user: 'username' host: 'localhost' (Got an error reading communication packets)
2017-03-03T16:47:49.582165Z 451 [Note] Aborted connection 451 to db: 'central' user: 'username' host: 'localhost' (Got an error reading communication packets)
so the question is what have I done wrong?
Note i tried adding
$res->free();
$stmt->close();
this then resulted in
Packets out of order. Expected 1 received 7. Packet size=7
mysqli_stmt::execute(): MySQL server has gone away
mysqli_stmt::execute(): Error reading result set's header
from info.php
PHP Version 5.6.27
mysqli
MysqlI Support enabled
Client API library version mysqlnd 5.0.11-dev - 20120503 - $Id: 76b08b24596e12d4553bd41fc93cccd5bac2fe7a $
Active Persistent Links 0
Inactive Persistent Links 0
Active Links 0
Directive Local Value Master Value
mysqli.allow_local_infile On On
mysqli.allow_persistent On On
mysqli.default_host no value no value
mysqli.default_port 3306 3306
mysqli.default_pw no value no value
mysqli.default_socket no value no value
mysqli.default_user no value no value
mysqli.max_links Unlimited Unlimited
mysqli.max_persistent Unlimited Unlimited
mysqli.reconnect Off Off
mysqli.rollback_on_cached_plink Off Off