<bdo id='W8pPQ'></bdo><ul id='W8pPQ'></ul>
    1. <i id='W8pPQ'><tr id='W8pPQ'><dt id='W8pPQ'><q id='W8pPQ'><span id='W8pPQ'><b id='W8pPQ'><form id='W8pPQ'><ins id='W8pPQ'></ins><ul id='W8pPQ'></ul><sub id='W8pPQ'></sub></form><legend id='W8pPQ'></legend><bdo id='W8pPQ'><pre id='W8pPQ'><center id='W8pPQ'></center></pre></bdo></b><th id='W8pPQ'></th></span></q></dt></tr></i><div id='W8pPQ'><tfoot id='W8pPQ'></tfoot><dl id='W8pPQ'><fieldset id='W8pPQ'></fieldset></dl></div>

      <small id='W8pPQ'></small><noframes id='W8pPQ'>

        <legend id='W8pPQ'><style id='W8pPQ'><dir id='W8pPQ'><q id='W8pPQ'></q></dir></style></legend>
        <tfoot id='W8pPQ'></tfoot>

        pdo 直接将图像插入数据库 - 始终插入 BLOB - 0B

        时间:2023-10-04

        1. <legend id='sTpkE'><style id='sTpkE'><dir id='sTpkE'><q id='sTpkE'></q></dir></style></legend>
          <i id='sTpkE'><tr id='sTpkE'><dt id='sTpkE'><q id='sTpkE'><span id='sTpkE'><b id='sTpkE'><form id='sTpkE'><ins id='sTpkE'></ins><ul id='sTpkE'></ul><sub id='sTpkE'></sub></form><legend id='sTpkE'></legend><bdo id='sTpkE'><pre id='sTpkE'><center id='sTpkE'></center></pre></bdo></b><th id='sTpkE'></th></span></q></dt></tr></i><div id='sTpkE'><tfoot id='sTpkE'></tfoot><dl id='sTpkE'><fieldset id='sTpkE'></fieldset></dl></div>
            <bdo id='sTpkE'></bdo><ul id='sTpkE'></ul>

                    <tbody id='sTpkE'></tbody>
                • <small id='sTpkE'></small><noframes id='sTpkE'>

                • <tfoot id='sTpkE'></tfoot>
                • 本文介绍了pdo 直接将图像插入数据库 - 始终插入 BLOB - 0B的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试将图像直接插入到 mysql 数据库表中.在我的数据库中,我总是得到 [BLOB - 0B].它不会将图像插入表格中.我也没有收到任何错误.我糊涂了..

                  I'm trying to insert the image into mysql database table directly. In my database I'm always getting [BLOB - 0B]. it doesn't insert images into table. I didn't get any error too. I'm confused..

                  PHP

                  ini_set('display_startup_errors',1);
                      ini_set('display_errors',1);
                      error_reporting(-1);
                  
                      include('config.php');
                       if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) 
                        { 
                            $tmpName  = $_FILES['image']['tmp_name'];  
                  
                            $fp = fopen($tmpName, 'r');
                            $data = fread($fp, filesize($tmpName));
                            $data = addslashes($data);
                            fclose($fp);
                        } 
                  
                        try
                          {
                              $stmt = $conn->prepare("INSERT INTO images ( picture ) VALUES ( '$data' )");
                  //          $stmt->bindParam(1, $data, PDO::PARAM_LOB);
                              $conn->errorInfo();
                              $stmt->execute();
                          }
                          catch(PDOException $e)
                          {
                              'Error : ' .$e->getMessage();
                          }
                  

                  HTML

                  <form action="upload.php" method="post">
                  <input id="image" name="image" type="file" />
                  <input type="submit" value="Upload" />
                  </form>
                  

                  推荐答案

                  你差不多明白了,你想让 PDO::PARAM_LOB 成为你上面创建的文件指针,而不是读取的结果fp

                  You almost got it, you want PDO::PARAM_LOB to be a file pointer which you created above, not the result of reading the fp

                  if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) 
                  { 
                     $tmpName  = $_FILES['image']['tmp_name'];  
                  
                     $fp = fopen($tmpName, 'rb'); // read binary
                  } 
                  
                  try
                  {
                     $stmt = $conn->prepare("INSERT INTO images ( picture ) VALUES ( ? )");
                     $stmt->bindParam(1, $fp, PDO::PARAM_LOB);
                     $conn->errorInfo();
                     $stmt->execute();
                  }
                  catch(PDOException $e)
                  {
                     'Error : ' .$e->getMessage();
                  }
                  

                  这篇关于pdo 直接将图像插入数据库 - 始终插入 BLOB - 0B的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何使用 PDO bindParam 将点数据插入 mysql? 下一篇:类之间共享的 PDO 交互

                  相关文章

                  最新文章

                  <small id='W5WJ9'></small><noframes id='W5WJ9'>

                  <i id='W5WJ9'><tr id='W5WJ9'><dt id='W5WJ9'><q id='W5WJ9'><span id='W5WJ9'><b id='W5WJ9'><form id='W5WJ9'><ins id='W5WJ9'></ins><ul id='W5WJ9'></ul><sub id='W5WJ9'></sub></form><legend id='W5WJ9'></legend><bdo id='W5WJ9'><pre id='W5WJ9'><center id='W5WJ9'></center></pre></bdo></b><th id='W5WJ9'></th></span></q></dt></tr></i><div id='W5WJ9'><tfoot id='W5WJ9'></tfoot><dl id='W5WJ9'><fieldset id='W5WJ9'></fieldset></dl></div>

                  <tfoot id='W5WJ9'></tfoot>

                      <bdo id='W5WJ9'></bdo><ul id='W5WJ9'></ul>

                    1. <legend id='W5WJ9'><style id='W5WJ9'><dir id='W5WJ9'><q id='W5WJ9'></q></dir></style></legend>