odbc_prepare用于具有datetime输入参数的过程 [英] odbc_prepare for procedure with datetime input parameters

查看:182
本文介绍了odbc_prepare用于具有datetime输入参数的过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试执行需要日期时间输入参数的存储过程时,odbc_prepare语句有一些新问题,并且出现问题。

Somewhat new to odbc_prepare statements and am having an issue when trying to execute a stored procedure that requires datetime input parameters.

如果要使用odbc执行,而不使用下面显示的准备语句我没有问题...

If I am to execute using odbc without using the prepared statement as displayed below I have no issue...

$dblink = db_connect();
$query = "EXEC dbo.[ProcedureName] '" . $dateinput . "'";
odbc_exec($dblink, $query);

使用odbc_prepare我收到错误(仅适用于具有DateTime输入参数的过程)。下面的例子...

Using the odbc_prepare I'm getting an error (only for procedures with DateTime inputs parameters). Example below...

function execute_db($dblink, $query, $params){
   $n = sizeof($params);
   for($i=0; $i<$n; $i++){
        if($i != 0){
            $query = $query . ', ?';
        }
        else{
            $query  = $query . ' ?';
        }
    }

    $statement = odbc_prepare($dblink, $query);
    odbc_execute($statement, $params);

    return $statement;
}

$dblink = db_connect();
$query = "EXEC dbo.[ProcedureName]";
$params = array($dateinput);

$result = execute_db($dblink, $query, $params);

这将返回以下错误:


警告:odbc_execute():SQL错误:[Microsoft] [ODBC SQL Server
驱动程序]无效的角色值用于转换规范,SQL状态22005
在SQLExecute

Warning: odbc_execute(): SQL error: [Microsoft][ODBC SQL Server Driver]Invalid character value for cast specification, SQL state 22005 in SQLExecute

我传入的日期字符串是'mm / dd / yyyy'格式,并且没有使用准备就可以正常工作。有没有一个解决方法,除了更改存储过程的输入类型?

The date string I'm passing in is in 'mm/dd/yyyy' format and works fine without using prepare. Is there a workaround for this other than changing the stored procedure's input type?

推荐答案

使用适当的ODBC语法来调用一个过程,在日期时间使用正确的语法,它可能会让你进一步。调用语法是{call procname(arguments)}。 datetime语法为{ts''} - 请参阅日期,时间和时间戳转换序列 ODBC日期时间格式

Use the proper ODBC syntax for calling a procedure and use the proper syntax for date times and it might get you further. The call syntax is {call procname(arguments)}. The datetime syntax is {ts ''} - see Date, Time, and Timestamp Escape Sequences and ODBC Datetime Format

这篇关于odbc_prepare用于具有datetime输入参数的过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆