当前位置:网站首页>PHP PDO ODBC将一个文件夹的文件装载到MySQL数据库BLOB列,并将BLOB列下载到另一个文件夹
PHP PDO ODBC将一个文件夹的文件装载到MySQL数据库BLOB列,并将BLOB列下载到另一个文件夹
2022-04-23 15:25: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://blog.csdn.net/allway2/article/details/124361888
边栏推荐
- regular expression
- Machine learning - logistic regression
- Sword finger offer (1) -- for Huawei
- 22年了你还不知道文件包含漏洞?
- Set onedrive or Google drive as a drawing bed in upic for free
- Alexnet model
- Openfaas practice 4: template operation
- Design of digital temperature monitoring and alarm system based on DS18B20 single chip microcomputer [LCD1602 display + Proteus simulation + C program + paper + key setting, etc.]
- X509 certificate cer format to PEM format
- Llvm - generate for loop
猜你喜欢
The win10 taskbar notification area icon is missing
Lotus DB design and Implementation - 1 Basic Concepts
How to use OCR in 5 minutes
asp. Net method of sending mail using mailmessage
Krpano panorama vtour folder and tour
Advanced version of array simulation queue - ring queue (real queuing)
T2 iCloud日历无法同步
Kubernetes详解(九)——资源配置清单创建Pod实战
如何设计一个良好的API接口?
Detailed explanation of kubernetes (IX) -- actual combat of creating pod with resource allocation list
随机推荐
Have you learned the basic operation of circular queue?
深度学习——超参数设置
Mysql database explanation (VII)
Reptile exercises (1)
8.4 realization of recurrent neural network from zero
Introduction to dirty reading, unrepeatable reading and phantom reading
Hj31 word inversion
UML学习_day2
【backtrader源码解析18】yahoo.py 代码注释及解析(枯燥,对代码感兴趣,可以参考)
MySQL Basics
X509 certificate cer format to PEM format
A series of problems about the best time to buy and sell stocks
Collation of errors encountered in the use of redis shake
深度学习调参的技巧
Five data types of redis
Share 3 tools, edit 5 works at home and earn more than 400
22年了你还不知道文件包含漏洞?
Detailed explanation of C language knowledge points -- data types and variables [1] - carry counting system
Llvm - generate addition
Modify the default listening IP of firebase emulators