简体   繁体   中英

PDO integer converting integer on INSERT statement

I've got a PDO prepared statement which is trying to insert four items into a MySQL table. Three of the items are strings and are being inserted fine. The fourth is (in MySQL) an INT of length 3. In the PHP script the value is being declared as an integer :

$code = 200;

Then it along with the other parameters are being inserted via a prepared statement :

$stmt = $this->db->prepare('INSERT INTO table (value1,value2,value3,code) VALUES (:value1,:value2,:value3,:code)');
....(three bindValues for the other items)
$stmt->bindValue(':code', (int) $code, PDO::PARAM_INT);
$stmt->execute();

No matter what I try, though, whilst the insert statement is executed, within the database the value is coming out as 127, not 200.

I've tried pretty much every variety I think of, but it stubbornly refuses to go into the database as 200. Any suggestions?

I think you declared your table wrong. 127 is the max value of a tinyint, so it could be that your "integer" is a tinyinteger.

So edit your Database, please.

You have the column type tinyint. You can change the column type with the following query:

ALTER TABLE tablename MODIFY columnname INTEGER;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM