当前位置:网站首页>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
边栏推荐
- The life cycle of key value in redis module programming
- My raspberry PI zero 2W tossing notes record some problems encountered and solutions
- el-tree实现只显示某一级复选框且单选
- MySQL Basics
- Nacos程序连接MySQL8.0+ NullPointerException
- 字节面试 transformer相关问题 整理复盘
- The wechat applet optimizes the native request through the promise of ES6
- 8.5 concise implementation of cyclic neural network
- 移动app测试如何进行?
- How to write the keywords in the cover and title? As we media, why is there no video playback
猜你喜欢
Mysql database explanation (IX)
Detailed explanation of MySQL connection query
UML learning_ Day2
我的树莓派 Raspberry Pi Zero 2W 折腾笔记,记录一些遇到的问题和解决办法
My raspberry PI zero 2W tossing notes record some problems encountered and solutions
The wechat applet optimizes the native request through the promise of ES6
Advanced version of array simulation queue - ring queue (real queuing)
Squid agent
Kubernetes详解(十一)——标签与标签选择器
Sword finger offer (2) -- for Huawei
随机推荐
Deep learning - Super parameter setting
Collation of errors encountered in the use of redis shake
Crawling fragment of a button style on a website
nuxt项目:全局获取process.env信息
JS - implémenter la fonction de copie par clic
[thymeleaf] handle null values and use safe operators
On the day of entry, I cried (mushroom street was laid off and fought for seven months to win the offer)
Lotus DB design and Implementation - 1 Basic Concepts
Llvm - generate local variables
For 22 years, you didn't know the file contained vulnerabilities?
Mysql连接查询详解
Introduction to distributed transaction Seata
Example of time complexity calculation
移动app测试如何进行?
Node.js ODBC连接PostgreSQL
Reptile exercises (1)
Use of common pod controller of kubernetes
Basic operation of circular queue (Experiment)
调度系统使用注意事项
什么是CNAS认证?CNAS认可的软件测评中心有哪些?