5
responses

Hello

When I call sql_exec with a bind parameter

if (sql_exec("INSERT INTO Events (Id) VALUES(?)", $ID) == TRUE) {}

I get the following error:

INFO SQLBindParam failed; HY104:1:0:[Microsoft][ODBC SQL Server Driver] Invalid precision value

Same commnad using string concatenatiion works fine:

if (sql_exec("INSERT INTO Events (Id) VALUES(" + $ID +")") == TRUE) {}

Could you help me with it?

AskedJanuary 4, 2016 - 2:35pm

Comments (5)

  • adm's picture
    (NXLog)

    When inserting an integer the module expects BIGINT for the column and you have SMALLINT in your schema. This could result in loss of precision and I think this is what's causing the error.

  • michaels's picture

    Unfortunately it doesn't work.

    If I bind a constant number instead of the variable, it works even for smallint.

    String concatenation works as well.

  • adm's picture
    (NXLog)

    Just ran into a similar issue.  $ID is most likely a string here and you need to convert it to an integer first. The following should help.

    if (sql_exec("INSERT INTO Events (Id) VALUES(?)", integer($ID)) == TRUE) {}

Answers (0)