php access 插入,如何使用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.

我需要將從HTML表單上傳的一些文件添加到MS Access DDBB。使用PHP,SQL和ODBC我沒有任何問題查詢Access文件,附件字段除外。

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.

無論我放什么而不是“Wathever”,錯誤總是一樣的。除非它是一個空字符串,否則查詢運行沒有問題,並且實際上正常工作,如下圖所示。

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?

有什么想法我應該在查詢中使它工作,或任何其他方式將附件插入MS Access DDBB?

Thanks

謝謝

2 个解决方案

#1

2

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

Erik是對的:您無法使用ODBC插入附件。您需要使用Access DAO,如下所示:

$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.

請注意Access DAO是Access數據庫引擎的一個組件,因此這種方法不需要完全安裝Microsoft Access應用程序。

#2

1

As far as I know, this is not possible when only using PHP and ODBC. You will need something that can interface directly with Access through COM or the command-line.

據我所知,僅使用PHP和ODBC時,這是不可能的。您將需要能夠通過COM或命令行直接與Access連接的東西。

You could create a macro to either import all files from a certain folder in Access, or to listen to the command-line and import a single file. Then you could trigger that using shell_exec in PHP. That means you will need to have Access on the server running the commands.

您可以創建一個宏來從Access中的某個文件夾導入所有文件,或者監聽命令行並導入單個文件。然后你可以在PHP中使用shell_exec觸發它。這意味着您需要在運行命令的服務器上安裝Access。

It isn't easy. I can give you pointers on steps if you really want to do this.

這並不容易。如果你真的想這樣做,我可以給你指出步驟。

See this google discussion where a Microsoft employee stated ACE ODBC has no support for attachment fields.

請參閱此谷歌討論,其中Microsoft員工聲明ACE ODBC不支持附件字段。

(If someone does know a way, I'd be happy to be corrected)

(如果有人知道某種方式,我很樂意得到糾正)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值