我正在使用PDO绑定参数直接更新MySQL数据库。更新成功,并在 - > execute()之后放置一个打印语句;工作正常,但当php尝试退出时,我得到一个malloc错误,php进程被其父进程中止。
代码如下:
<?php
$edit_type = 'Edit';
$employeeID = 1;
$surname = 'Green';
$givenname = 'Frodo';
$degree = 'PhD';
$title = 'Some_Title';
$division = 'Some_Division';
$office_phone = 'number';
$email = 'adress@someplace.foo';
$room = 'abc-123';
$PI_ID = 1;
$confirmDeactivate = 'Do Not Deactivate';
// Establish a MySQL Connection
try {
$cvbrdbh_update = new PDO("mysql:host={$_SERVER['MYSQL_SERVER']};dbname={$_SERVER['MYSQL_DB']}",$_SERVER['MYSQL_USER'],$_SERVER['MYSQL_PASSWORD'], array(PDO::ATTR_PERSISTENT => true));
$cvbrdbh_update->exec("SET CHARACTER SET utf8");
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "\n" ;
die();
}
$cvbrdbh_update->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$cvbrdbh_update->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if ($employeeID && $edit_type == "Edit") {
if (empty($surname)) {
print "Warning! The Surname field was empty. Please restart the editing process and be sure to fill in a surname.";
} else {
$person_update_stmt = $cvbrdbh_update->prepare("UPDATE employees, med_division, titles, pi_emp SET Surname=:surname, GivenName=:givenname, Degree=:degree, Office_Phone=:office_phone, Email=:email, Room=:room, Division=:division, Title=:title, med_division.PI_ID=:pi_id1, pi_emp.PI_ID=:pi_id2 WHERE employees.EmployeeID = '$employeeID' AND med_division.EmployeeID = '$employeeID' AND titles.EmployeeID = '$employeeID' AND pi_emp.EmployeeID = '$employeeID'");
$person_update_stmt->bindValue(':surname',$surname,PDO::PARAM_STR);
$person_update_stmt->bindValue(':givenname',$givenname,PDO::PARAM_STR);
$person_update_stmt->bindValue(':degree',$degree,PDO::PARAM_STR);
$person_update_stmt->bindValue(':office_phone',$office_phone,PDO::PARAM_STR);
$person_update_stmt->bindValue(':email',$email,PDO::PARAM_STR);
$person_update_stmt->bindValue(':room',$room,PDO::PARAM_STR);
$person_update_stmt->bindValue(':division',$division,PDO::PARAM_STR);
$person_update_stmt->bindValue(':title',$title,PDO::PARAM_STR);
$person_update_stmt->bindValue(':pi_id1',$PI_ID,PDO::PARAM_STR);
$person_update_stmt->bindValue(':pi_id2',$PI_ID,PDO::PARAM_STR);
$person_update_stmt->execute();
print "Finished" . "\n";
}
}
?>
由此,我获得了成功的数据库更新,它打印出“已完成”,然后出现以下错误消息:
鱼是我的贝壳。我的PHP版本是:php(12652)malloc: *对象0x116f07438的错误:释放的指针未分配 * 在malloc_error_break中设置断点以进行调试
fish:Job 1,'php database_write_probe.php'以SIGABRT信号终止(Abort)
PHP 5.3.15与Suhosin-Patch(cli)(内置:2012年8月24日17:45:44) 版权所有(c)1997-2012 PHP小组 Zend Engine v2.3.0,版权所有(c)1998-2012 Zend Technologies
我的MySQL版本是:
Ver 14.14使用readline 5.1为osx10.6(i386)分发5.5.27
非常感谢任何帮助。
编辑: 正如进一步的数据点,看起来精确的触发器是我使用“bindValue”。将它们取出并简单地将适当的变量插入“prepare”语句可以防止崩溃。所以我猜这是一个可能的解决方案,虽然有一个严重的安全问题。