2

I'm having trouble getting PDO prepared statements to work with SQL Server's non-traditional data types such as money. The database assumes the field is nvarchar even if it's cast as a float, and returns an error like:

Error converting data type nvarchar to money.

I'm used to MySQL and things "just working" so I'm a little lost.

$stmt = $pdo->prepare('EXEC my_money_sp ?');
$stmt->bindValue(1, 10.00);
$stmt->execute();
// SQLSTATE[42000]: [SQL Server]Error converting data type nvarchar to money.
fpcjh
  • 273
  • 5
  • 16
  • Try turning emulating prepares off and see if that makes a difference. – Mike Apr 27 '16 at 00:56
  • See also: http://stackoverflow.com/questions/582797/should-you-choose-the-money-or-decimalx-y-datatypes-in-sql-server – Mike Apr 27 '16 at 00:57
  • Emulated prepares are off. I don't have control over the database structure. – fpcjh Apr 27 '16 at 02:26
  • If you are unable to find an actual answer how to bind parameters to a money column as a workaround you may want to use [`PDO::quote`](http://php.net/manual/en/pdo.quote.php) and then just put the value right in the query. Of course you would lose any benefits from using prepared statements. – Mike Apr 27 '16 at 03:13
  • I also stumbled upon this question. It may help. http://stackoverflow.com/questions/18362908/convert-nvarchar-to-money-or-float-format. If not, you may also want to consider posting `my_money_sp` just to make sure there's no problem in your procedure that's causing this error. – Mike Apr 27 '16 at 03:14

0 Answers0