Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #15130
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: Appropriate PDO::PARAM_<what here> for monetary value |
| Date | 2015-03-23 21:23 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <meqe8k$37m$1@dont-email.me> (permalink) |
| References | <f4e9620d-19da-402a-94e5-de45797377f3@googlegroups.com> <meqbr0$rin$1@dont-email.me> <9fc7ffe3-e295-436f-904f-a368b7a2084c@googlegroups.com> |
On 3/23/2015 8:56 PM, Fernando Basso wrote: > On Monday, March 23, 2015 at 9:42:05 PM UTC-3, Jerry Stuckle wrote: >> On 3/23/2015 7:23 PM, Fernando Basso wrote: >>> Suppose I have this situation: >>> >>> $price = '33.99'; >>> $sth = $db->prepare( $sql ); >>> $sth->bindParam( ':price', $price, PDO::PARAM_<what here?> >>> >>> What is the appropriate PDO param constant for that situation? >>> >> >> It all depends on what the type in the database is. Is it a numeric >> type such as FLOAT or DOUBLE? Or is it a string type such as VARCHAR? > > In this case it is MariaDB, and the type of that specific > column is NUMERIC(8,2). I failed to find something that seemed > appropriate http://php.net/manual/en/pdo.constants.php > >> The type here needs to match what's in the database. >> I can't answer for MariaDB - never used it. However, I think it's still close enough to MySQL. The problem is there is no NUMERIC (DECIMAL) equivalent in PHP (or most languages, for that matter). So in PHP you have to store/retrieve the value as a string (PDO::PARAM_STR). Just remember that when converting to/from a floating point value in PHP, most decimal values do not have an exact representation. -- ================== Remove the "x" from my email address Jerry Stuckle jstucklex@attglobal.net ==================
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Appropriate PDO::PARAM_<what here> for monetary value Fernando Basso <fernandobasso.br@gmail.com> - 2015-03-23 16:23 -0700
Re: Appropriate PDO::PARAM_<what here> for monetary value Jerry Stuckle <jstucklex@attglobal.net> - 2015-03-23 20:41 -0400
Re: Appropriate PDO::PARAM_<what here> for monetary value Fernando Basso <fernandobasso.br@gmail.com> - 2015-03-23 17:56 -0700
Re: Appropriate PDO::PARAM_<what here> for monetary value Jerry Stuckle <jstucklex@attglobal.net> - 2015-03-23 21:23 -0400
Re: Appropriate PDO::PARAM_<what here> for monetary value Fernando Basso <fernandobasso.br@gmail.com> - 2015-03-24 10:42 -0700
csiph-web