当前位置:网站首页>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
边栏推荐
- Set onedrive or Google drive as a drawing bed in upic for free
- Have you really learned the operation of sequence table?
- Common interview questions of operating system:
- JS -- realize click Copy function
- Sword finger offer (1) -- for Huawei
- 软件性能测试报告起着什么作用?第三方测试报告如何收费?
- Summary of interfaces for JDBC and servlet to write CRUD
- Design of digital temperature monitoring and alarm system based on DS18B20 single chip microcomputer [LCD1602 display + Proteus simulation + C program + paper + key setting, etc.]
- 群体智能自主作业智慧农场项目启动及实施方案论证会议
- 深度学习调参的技巧
猜你喜欢
8.2 text preprocessing
Lotus DB design and Implementation - 1 Basic Concepts
G007-hwy-cc-estor-03 Huawei Dorado V6 storage simulator construction
8.4 realization of recurrent neural network from zero
Krpano panorama vtour folder and tour
Reptile exercises (1)
What exactly does the distributed core principle analysis that fascinates Alibaba P8? I was surprised after reading it
TLS / SSL protocol details (30) RSA, DHE, ecdhe and ecdh processes and differences in SSL
On the day of entry, I cried (mushroom street was laid off and fought for seven months to win the offer)
My raspberry PI zero 2W toss notes to record some problems and solutions
随机推荐
8.2 text preprocessing
Squid agent
Share 20 tips for ES6 that should not be missed
redis-shake 使用中遇到的错误整理
Nacos program connects to mysql8 0+ NullPointerException
【Leetcode-每日一题】安装栅栏
SSH connects to the remote host through the springboard machine
How to design a good API interface?
Redis cluster principle
My raspberry PI zero 2W tossing notes record some problems encountered and solutions
API gateway / API gateway (II) - use of Kong - load balancing
My raspberry PI zero 2W toss notes to record some problems and solutions
JUC learning record (2022.4.22)
Wechat applet customer service access to send and receive messages
Ffmpeg installation error: NASM / yasm not found or too old Use --disable-x86asm for a clipped build
Design of digital temperature monitoring and alarm system based on DS18B20 single chip microcomputer [LCD1602 display + Proteus simulation + C program + paper + key setting, etc.]
A series of problems about the best time to buy and sell stocks
asp. Net method of sending mail using mailmessage
自动化测试框架常见类型▏自动化测试就交给软件测评机构
8.3 language model and data set