Wednesday 15 April 2015

php - PDO executing statement that mysql cli cannot -



php - PDO executing statement that mysql cli cannot -

i have database table unsigned int represents wallet balance. column called wallet. in table called users.

the next query fails via mysql cli:

update users set wallet = `wallet` - 550000000 username = 'user'

with error message:

error 1690 (22003): bigint unsigned value out of range in '(database.users.wallet - 550000000)'

the issue is, when executed via pdo errmode_exception, brings wallet balance 0 , continues execution without raising mentioned error in exception

select @@sql_mode returns nil in both code , mysql cli.

here function creates database handle , returns query object

//this function connects database public function connect($dbname,dbconfig $config = null) { //if connection set homecoming if(isset($this->dbs[$dbname])) homecoming $this->dbs[$dbname]; //if config object not set, , still null, throw exception if(!isset($this->_config[$dbname])) { if($config === null) throw new pdodatabasesexception('database configuration object not set',1); $this->_config[$dbname] = $config; } $config = $this->_config[$dbname]; //create pdo object $this->dbs[$dbname] = new pdo( $config::type . ':host=' . $config::$host . ';port=' . $config::$port . ';dbname=' . $dbname, $config::$user, $config::$password ); //tell handle throw exceptions $this->dbs[$dbname]->setattribute( pdo::attr_errmode, pdo::errmode_exception ); $this->dbs[$dbname]->setattribute( pdo::attr_emulate_prepares, false ); //return reference newly created pdo object homecoming $this->dbs[$dbname]; } //end connect()

trying save need paste bunch of unnecessary code.. query object takes database handle above, , prepares , executes statement:

'update users set wallet = wallet - ? id = ?'

binding amount (approximately 10 million) , user id, executing.

wallet balance can @ 0 , query still execute successfully. why happen when cli cannot? not create sense!!

i believe need 1 time 1 time again reiterate this query should fail if drops wallet below 0!

it succeeds through pdo, not through mysql cli, question why??

the result of wallet - 550000000 should less 0 , column unsigned. seek alter column type bigint unsigned bigint

php mysql pdo

No comments:

Post a Comment