dtiopy6088 2017-08-18 17:16
浏览 68
已采纳

如何使用PHP将附件插入Access数据库?

I need to add some files uploaded from an HTML form to an MS Access DDBB. Using PHP, SQL and ODBC I haven't had any problem queryng to the Access file, except for attachment fields.

INSERT INTO TEMAS (DATOSADJUNTOS.FILENAME, DATOSADJUNTOS.FILEDATA) VALUES ("ExampleName.txt", "Wathever") WHERE ID = 4;

This query returns the following error:

SQLSTATE[07009]: Invalid descriptor index: -1003 [Microsoft][Controlador ODBC Microsoft Access] Argumento no válido. (SQLExecute[-1003] at ext\pdo_odbc\odbc_stmt.c:260)

No matter what I put instead of "Wathever", the error is always the same. Except if it is an empty string, then the query runs with no problem, and actually works, as you can see in the next image.

Any idea of what should I put in the query to make it work, or any other way of inserting an attachment into a MS Access DDBB?

Thanks

  • 写回答

2条回答 默认 最新

  • doupao6011 2017-08-19 13:58
    关注

    Erik is right: You can't insert an Attachment using ODBC. You need to use Access DAO, like so:

    $dbe = new COM("DAO.DBEngine.120") or die("Cannot create DBEngine object.");
    $db = $dbe->OpenDatabase("C:\\Users\\Public\\Database1.accdb");
    $rsMain = $db->OpenRecordset("SELECT DATOSADJUNTOS FROM TEMAS WHERE ID=4", 2);  // dbOpenDynaset
    $rsMain->Edit;
    $rsAttach = $rsMain->Fields("DATOSADJUNTOS")->Value;
    $rsAttach->AddNew;
    $fldAttach = $rsAttach->Fields("FileData");
    $fldAttach->LoadFromFile("C:\\Users\\Gord\\Desktop\\sample.pdf");
    $rsAttach->Update;
    $rsAttach->Close;
    $rsMain->Update;
    $rsMain->Close;
    $db->Close;
    

    Note that Access DAO is a component of the Access Database Engine, so this approach does not require a full install of the Microsoft Access application.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 FileNotFoundError 解决方案
  • ¥15 uniapp实现如下图的图表功能
  • ¥15 u-subsection如何修改相邻两个节点样式
  • ¥30 vs2010开发 WFP(windows filtering platform)
  • ¥15 服务端控制goose报文控制块的发布问题
  • ¥15 学习指导与未来导向啊
  • ¥15 求多普勒频移瞬时表达式
  • ¥15 如果要做一个老年人平板有哪些需求
  • ¥15 k8s生产配置推荐配置及部署方案
  • ¥15 matlab提取运动物体的坐标