PDO 插入错误:OCIStmtExecute:ORA-12899:值对于列来说太大
我遇到 PDO 插入问题。这是我的代码片段。它将数据值(由用户提交)绑定到数据参数;
...
if((is_int($actualVal)) || ($actualVal ==NULL)){
print $actualVal .' is INT<br>';
$objStatement->bindValue(':'. $value, $actualVal, PDO::PARAM_INT);
}
else {
print $actualVal .' is STR<br>';
$objStatement->bindValue(':'. $value, $actualVal, PDO::PARAM_STR);
};
例如,当我提供以下数据值时:
$objRental->setRentalFacultyId('29');
$objRental->setRentalResCenterId(17);
$objRental->setRentalPurpose("purpose");
$objRental->setRentalDateReturned("2011-10-01");
$objRental->setRentalDateRented("2008-01-05");
$objRental->setRentalDateSaved("2001-12-12");
$objRental->setRentalUserIdSaved('3');
$objRental->setRentalReturnStatus('Y');
$objRental->setRentalSupervisorId('5');
我得到的结果和错误为: 结果:
int 23
23 is INT
string 'purpose' (length=7)
purpose is STR
int 17
17 is INT
int 29
29 is INT
string '2008-01-05' (length=10)
2008-01-05 is STR
string '2011-10-01' (length=10)
2011-10-01 is STR
string '2001-12-12' (length=10)
2001-12-12 is STR
int 5
5 is STR
int 3
3 is STR
string 'Y' (length=1)
Y is STR
错误:
SQLSTATE[HY000]:一般错误:12899 OCIStmtExecute:ORA-12899:列“.....”的值太大(实际:19,最大值:15)(ext \ pdo_oci \ oci_statement.c:146)
问题似乎我认为发生这种情况是因为 PDO 正在改变我的数据值的数据长度。我该如何解决这个问题?
I have a PDO insert problem. Here is my code snippet. It binds the data value (submitted by user) to the data params;
...
if((is_int($actualVal)) || ($actualVal ==NULL)){
print $actualVal .' is INT<br>';
$objStatement->bindValue(':'. $value, $actualVal, PDO::PARAM_INT);
}
else {
print $actualVal .' is STR<br>';
$objStatement->bindValue(':'. $value, $actualVal, PDO::PARAM_STR);
};
For instance when I provide the following data values:
$objRental->setRentalFacultyId('29');
$objRental->setRentalResCenterId(17);
$objRental->setRentalPurpose("purpose");
$objRental->setRentalDateReturned("2011-10-01");
$objRental->setRentalDateRented("2008-01-05");
$objRental->setRentalDateSaved("2001-12-12");
$objRental->setRentalUserIdSaved('3');
$objRental->setRentalReturnStatus('Y');
$objRental->setRentalSupervisorId('5');
I get the results and error as:
results:
int 23
23 is INT
string 'purpose' (length=7)
purpose is STR
int 17
17 is INT
int 29
29 is INT
string '2008-01-05' (length=10)
2008-01-05 is STR
string '2011-10-01' (length=10)
2011-10-01 is STR
string '2001-12-12' (length=10)
2001-12-12 is STR
int 5
5 is STR
int 3
3 is STR
string 'Y' (length=1)
Y is STR
Error:
SQLSTATE[HY000]: General error: 12899 OCIStmtExecute: ORA-12899: value too large for column "....." (actual: 19, maximum: 15) (ext\pdo_oci\oci_statement.c:146)
The problem seems to occur I think because PDO is changing that data length of my data value. How can I solve this?
你的表有这个:
你的 PHP 有这个:
但是然后我们看到了这个:
因此,rental_faculty_id 在到达数据库时需要是一个字符串,但有人将其转换为整数,因为
'29'
看起来像一个整数;有人很可能是这里的if
条件:如果你尝试为需要字符串的东西绑定一个数字,你会得到奇怪的行为。
您应该使用数据库架构(而不是传入数据)来确定是否应该与
PDO::PARAM_INT
或PDO::PARAM_STR
绑定。is_int
函数应该返回 false'29'
所以也许在setRentalFacultyId
调用和上面的if
语句之间试图变得“聪明”。Your table has this:
And your PHP has this:
But then we see this:
So the rental_faculty_id needs to be a string when it gets to the database but someone is converting it to an integer because
'29'
looks like an integer; that someone is most likely theif
condition in this:If you try to bind a number for something that expects a string, you'll get odd behavior.
You should be using the database schema — not the incoming data — to determine if you should bind with
PDO::PARAM_INT
orPDO::PARAM_STR
. Theis_int
function should be returning false for'29'
so maybe something is trying to be "clever" between thesetRentalFacultyId
call and the aboveif
statement.