dqlxtv1452 2015-10-23 19:11
浏览 40
已采纳

将日期传递给PHP中的ADO命令对象参数

I have code that looks something like this:

$cmd = new com('ADODB.command');
$cmd->activeConnection = $CONNECTION;
$sql = 'UPDATE MyTable SET WhenPlanned = ? WHERE ID = ?';
$cmd->commandText = $sql;
$p1 = $cmd->createParameter('WhenPlanned', adDate, adParamInput, 0, $dateVal)
$p2 = $cmd->createParameter('ID', adInteger, adParamInput, 4, $intVal); 
$cmd->parameters->append($p1);
$cmd->parameters->append($p2);
$cmd->execute();

This only produces the following error: PHP Fatal error: Uncaught exception 'com_exception' with message 'Source: ADODB.Command Description: Application uses a value of the wrong type for the current operation.'

The $dateVal variable is a string representation of a date. I've tried creating a PHP datetime object to pass to no avail...Does anyone know how to pass in a date that the ADO Parameter will accept as an argument in PHP? Thanks!

  • 写回答

1条回答 默认 最新

  • doumiang0597 2015-10-28 16:31
    关注

    I created a test table to isolate and experiment with date parameters and found something that worked. I guess it's a date formatting issue. I was passing in dates that looked like the string in the date() function below without formatting.

    $cmd = new com('ADODB.command');
    $cmd->activeConnection = $CONNECTION[SYSTEM];
    $sql = 'INSERT INTO TestDateTable (testdate) VALUES (?)';
    $cmd->commandText = $sql;
    $d = date('Y-m-d H:i:s', strtotime('10/26/2015'));
    $p1 = $cmd->createParameter('testdate', adDate, adParamInput, 0,  $d);
    $cmd->parameters->append($p1);
    $cmd->execute();
    

    This successfully inserted a date in my table.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度