0
answers

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)

    Can you also show the schema (or at least the type of the Events.Id column)?

    January 4, 2016 - 11:00pm
  • michaels's picture

    CREATE TABLE [dbo].[Events](

            [Id] [smallint] NOT NULL

    ) ON [PRIMARY]

     

    January 6, 2016 - 10:21am
  • 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.

    January 7, 2016 - 10:50am
  • 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.

    January 7, 2016 - 2:59pm
  • 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) {}

    March 16, 2016 - 11:24am

Answers (0)