当前位置:网站首页>PHP PDO ODBC loads files from one folder into the blob column of MySQL database and downloads the blob column to another folder
PHP PDO ODBC loads files from one folder into the blob column of MySQL database and downloads the blob column to another folder
2022-04-23 15:26:00 【allway2】
<?php
$hostname = "localhost";
$database = "db";
$username = "root";
$password = "root";
try {
$pdo = new PDO("odbc:Driver={MySQL ODBC 3.51 Driver};host=$hostname;database=$database", $username, $password);
} catch (PDOException $e) {
echo $e->getMessage();
}
$arrFiles = array();
$iterator = new FilesystemIterator("InputFiles");
foreach ($iterator as $entry) {
$arrFiles[] = $entry->getFilename();
echo ( $entry->getFilename());
echo ( $entry->getPathname());
$blob = fopen($entry->getPathname(), 'rb');
$sql = "INSERT INTO gallery(name,image) VALUES(:name,:image)";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':name', $entry->getFilename());
$stmt->bindParam(':image', $blob, PDO::PARAM_LOB);
$stmt->execute();
}
?>
<?php
$hostname = "localhost";
$database = "db";
$username = "root";
$password = "root";
try {
$pdo = new PDO("odbc:Driver={MySQL ODBC 3.51 Driver};host=$hostname;database=$database", $username, $password);
} catch (PDOException $e) {
echo $e->getMessage();
}
$sql = "SELECT name,image FROM gallery";
$stmt = $pdo->query($sql);
while ($row = $stmt->fetch()) {
$filehandle = fopen("DownLoadFiles/" . $row[name], 'wb');
fwrite($filehandle, $row[image]);
fclose($filehandle);
}
?>
版权声明
本文为[allway2]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231525131193.html
边栏推荐
- Byte interview programming question: the minimum number of K
- How to design a good API interface?
- 软件性能测试报告起着什么作用?第三方测试报告如何收费?
- asp. Net method of sending mail using mailmessage
- 电脑怎么重装系统后显示器没有信号了
- 激活函数的优缺点和选择
- Thinkphp5 + data large screen display effect
- How to design a good API interface?
- Share 20 tips for ES6 that should not be missed
- Async void caused the program to crash
猜你喜欢
For 22 years, you didn't know the file contained vulnerabilities?
Basic operation of sequential stack
What exactly does the distributed core principle analysis that fascinates Alibaba P8? I was surprised after reading it
What is the role of the full connection layer?
nuxt项目:全局获取process.env信息
Detailed explanation of C language knowledge points -- first understanding of C language [1] - vs2022 debugging skills and code practice [1]
我的 Raspberry Pi Zero 2W 折腾笔记,记录一些遇到的问题和解决办法
TLS / SSL protocol details (30) RSA, DHE, ecdhe and ecdh processes and differences in SSL
Openfaas practice 4: template operation
Tun model of flannel principle
随机推荐
X509 certificate cer format to PEM format
Llvm - generate local variables
【Leetcode-每日一题】安装栅栏
Byte interview programming question: the minimum number of K
How to design a good API interface?
Openfaas practice 4: template operation
Set onedrive or Google drive as a drawing bed in upic for free
YML references other variables
C语言超全学习路线(收藏让你少走弯路)
群体智能自主作业智慧农场项目启动及实施方案论证会议
Mysql database explanation (IX)
asp. Net method of sending mail using mailmessage
My raspberry PI zero 2W toss notes to record some problems and solutions
Fill in the next right node pointer II of each node [classical hierarchy traversal | regarded as linked list]
Detailed explanation of kubernetes (IX) -- actual combat of creating pod with resource allocation list
Leetcode学习计划之动态规划入门day3(198,213,740)
How to write the keywords in the cover and title? As we media, why is there no video playback
Compiling OpenSSL
G007-hwy-cc-estor-03 Huawei Dorado V6 storage simulator construction
T2 iCloud日历无法同步