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 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序