gpt4 book ai didi

mysql - 如何在vb6中上传图片并放入mysql数据库中?

转载 作者:行者123 更新时间:2023-11-29 09:09:44 25 4
gpt4 key购买 nike

有谁知道如何用vb6上传图片并可以将其放入mysql数据库吗?

示例代码就可以了。

最佳答案

我不知道你是如何连接VB6和MySQL的,但解决方案如下:步骤1.使用Mediumblob创建一个表来存储文件,如下

CREATE TABLE files(
file_id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
file_name VARCHAR(64) NOT NULL,
file_size MEDIUMINT UNSIGNED NOT NULL,
file MEDIUMBLOB NOT NULL
);

步骤 2. 连接到 MySQL,您可以使用您的连接方法

DRIVER={MySQL ODBC 3.51 Driver}; SERVER=123.456.789.100; DATABASE=mysqldatabase; UID=sampleuser; PWD=12345; OPTION=16427
Dim conn As ADODB.Connection
Set conn = New ADODB.Connection
conn.ConnectionString = GloConnectionString
conn.CursorLocation = adUseClient
conn.Open

第3步:向MySQL发送数据并关闭连接

Dim rs As  ADODB.Recordset
Set rs = New ADODB.Recordset
Dim mystream As ADODB.Stream
Set mystream = New ADODB.Stream
mystream.Type = adTypeBinary
rs.Open "SELECT * FROM files WHERE 1=0", conn, adOpenStatic, adLockOptimistic
rs.AddNew
mystream.Open
mystream.LoadFromFile "c:\\myimage.gif"
rs!file_name = "myimage.gif"
rs!file_size = mystream.size
rs!file = mystream.read
rs.Update
mystream.Close
rs.Close
conn.Close

第 4 步:从 MySQL 恢复数据

Dim conn As New ADODB.Connection
conn.ConnectionString = GloConnectionString
conn.CursorLocation = adUseClient
conn.Open
Dim rs As New ADODB.Recordset
Dim mystream As New ADODB.Stream
mystream.Type = adTypeBinary
rs.Open "SELECT * FROM files WHERE files.file_id = 1", conn
mystream.Open
mystream.Write rs!File
mystream.SaveToFile "c:\\newimage.gif", adSaveCreateOverWrite
mystream.close
rs.Close
conn.Close

关于mysql - 如何在vb6中上传图片并放入mysql数据库中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5981042/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com