douye6812 2015-08-20 13:07
浏览 97

使用Laravel 5.1在Sybase int列中插入问题

I'm having problems to insert values in tables with integer data type columns using Laravel 5.1 and Sybase.

The error 257 is listed when in an exception. In Sybases's docs it seems to be a conversion problem. I can see the insert sql builded by the framework is something like

insert into [table_name] ([col1], [col2]) values ('AAA', '999'))

So, I can see that Laravel is passing all value into single quotes, and seems to me that Sybase do not accept this kind of construction.

I 'm using Linux Ubuntu with freetds installed with the 5.0 protocol version.

Someone has solved this kind of problem already? Am I missing some configuration or do I have to write an driver extension for Sybase work with Laravel 5.1?

  • 写回答

1条回答 默认 最新

  • dongzhuo1958 2015-10-28 19:28
    关注

    Assuming you are using Sybase ASE, the problem is database specific and it is inherited from PHP PDO whereby it by default will bind all parameters as string unless you specify the data type to bind using the bindValue() function

    <?php
    /* Execute a prepared statement by binding PHP variables */
    $calories = 150;
    $colour = 'red';
    $sth = $dbh->prepare('SELECT name, colour, calories
        FROM fruit
        WHERE calories < :calories AND colour = :colour');
    $sth->bindValue(':calories', $calories, PDO::PARAM_INT);
    $sth->bindValue(':colour', $colour, PDO::PARAM_STR);
    $sth->execute();
    ?>
    

    The datatype must match your table definition.

    In Laravel, if you are using eloquent you may need to rewrite the Connection.php to bind the parameter accordingly due to current code in laravel does not use bindValue to bind the parameters and as such, PDO will use the default datatype which is a string.

    评论

报告相同问题?

悬赏问题

  • ¥15 对于这个问题的代码运行
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败