我工作的一个PHP应用程序,我尝试使用的mysqli与功能赢得成功:mysqli_stmt_bind_param:类型不匹配不会引发错误
function executeUpdateInsert($SQLStatement, $SQLBindString, $bindValueArray){
$ret = -1;
$dbConnection = getDbConnection();
$stmt = mysqli_prepare($dbConnection, $SQLStatement);
$bindParamArray = array_merge(array($stmt, $SQLBindString), $bindValueArray);
call_user_func_array (mysqli_stmt_bind_param , $bindParamArray);
if(mysqli_stmt_execute($stmt)) {
$ret = mysqli_insert_id ($dbConnection);
mysqli_stmt_close($stmt);
$dbConnection->close();
}else{
mysqli_stmt_close($stmt);
$dbConnection->close();
}
return $ret;
}
函数调用看起来像:
executeUpdateInsert("UPDATE mytable(int1, int2, string2)VALUES (?,?,?)", "iis", array (12,42,"string")));
这实际上是工作,虽然我发现一个非常奇怪的行为,当我尝试在数据库中插入非整数像125r896
值。在一个完美的世界中,我期望mysqli_stmt_execute($stmt)
返回FALSE
并失败,但不是它会在整数字段中插入125。
我是不是做了一些不正确的事,或者它是PHP + MySQL语句对象的正常行为?
因为我清楚地认为,作为一个错误,而不是一个功能。
它将值'125r896'投射到一个int,并给你125. –