drbuowqe02101 2018-04-20 11:11
浏览 64

使用PDO :: PARAM_LOB将图像上传到MariaDB表中的INSERT失败

My problem is that when I use the PDO::PARAM_LOB parameter in the bindParam() method the photo sent from the html form isn’t inserted in the MariaDB table. phpMyAdmin subsequently shows the table column ‘photo’ to be empty. The image is successfully inserted in the table when I don’t use the PDO::PARAM_LOB but this causes a Notice: Array to string conversion in C:\xampp\htdocs\TestSite\php-sellform-handler.php on line 80 to display to the user on the web page. There are other fields on the same form (which for simplicity I haven’t shown) which upload text and use PDO::PARAM_STR. This text data is always successfully inserted in the same table. How do I get insert to work using PDO::PARAM_LOB?

The nearest problem to mine that I can find on S/O is PHP/PDO/MySQL: inserting into MEDIUMBLOB stores bad data However that involves the image actually being inserted in the table, but in a corrupted form.

I’m using Apache/2.4.29 (Win32) OpenSSL/1.1.0g PHP/7.2.2 and 10.1.30-MariaDB

Here is my code:

$host = '127.0.0.1';
$db = 'test_db2';
$user = 'root';
$pass = '';
$charset = 'utf8mb4';

    $dsn = "mysql:host=$host;dbname=$db;charset=$charset";



$opt = [PDO::ATTR_ERRMODE =>PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
    PDO::ATTR_EMULATE_PREPARES => false 
    ];


$pdo=new PDO($dsn, $user, $pass, $opt);



if (isset($_FILES ['photo'])) {

$photo=$_FILES['photo'];


$stmt_user = $pdo->prepare("INSERT INTO users_table1(photo) VALUES(:photo)");

$stmt_user->bindParam(':photo', $photo, PDO::PARAM_LOB);    

$stmt_user->execute();
}

Thanks for any help!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
    • ¥15 错误 LNK2001 无法解析的外部符号
    • ¥50 安装pyaudiokits失败
    • ¥15 计组这些题应该咋做呀
    • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
    • ¥15 让node服务器有自动加载文件的功能
    • ¥15 jmeter脚本回放有的是对的有的是错的
    • ¥15 r语言蛋白组学相关问题