Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #15127 > unrolled thread
| Started by | Fernando Basso <fernandobasso.br@gmail.com> |
|---|---|
| First post | 2015-03-23 16:23 -0700 |
| Last post | 2015-03-24 10:42 -0700 |
| Articles | 5 — 2 participants |
Back to article view | Back to comp.lang.php
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
| From | Fernando Basso <fernandobasso.br@gmail.com> |
|---|---|
| Date | 2015-03-23 16:23 -0700 |
| Subject | Appropriate PDO::PARAM_<what here> for monetary value |
| Message-ID | <f4e9620d-19da-402a-94e5-de45797377f3@googlegroups.com> |
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?
[toc] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2015-03-23 20:41 -0400 |
| Message-ID | <meqbr0$rin$1@dont-email.me> |
| In reply to | #15127 |
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? The type here needs to match what's in the database. -- ================== Remove the "x" from my email address Jerry Stuckle jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | Fernando Basso <fernandobasso.br@gmail.com> |
|---|---|
| Date | 2015-03-23 17:56 -0700 |
| Message-ID | <9fc7ffe3-e295-436f-904f-a368b7a2084c@googlegroups.com> |
| In reply to | #15128 |
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. > > -- > ================== > Remove the "x" from my email address > Jerry Stuckle > jstucklex@attglobal.net > ==================
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2015-03-23 21:23 -0400 |
| Message-ID | <meqe8k$37m$1@dont-email.me> |
| In reply to | #15129 |
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 ==================
[toc] | [prev] | [next] | [standalone]
| From | Fernando Basso <fernandobasso.br@gmail.com> |
|---|---|
| Date | 2015-03-24 10:42 -0700 |
| Message-ID | <ea01dbd4-e6ad-4d81-8e33-b1576c84c813@googlegroups.com> |
| In reply to | #15130 |
On Monday, March 23, 2015 at 10:23:27 PM UTC-3, Jerry Stuckle wrote: > 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). All right. While I was waiting for an answer, I went with PARAM_STR and it worked, which startled me a little bit. > Just remember that when converting to/from a floating point value in > PHP, most decimal values do not have an exact representation. Sure, I'll keep that in mind. Thanks a lot for your help and time. > -- > ================== > Remove the "x" from my email address > Jerry Stuckle > jstucklex@attglobal.net > ==================
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web