dongqianzhan8325 2018-10-10 19:52
浏览 58
已采纳

如何使用PHP上传文件 - Oracle中的ODBC?

I've been doing this, I know the connection works, and I'll test it in another project. but now I need to manipulate blob data in oraclo with php using ODBC, but I do not know how to do it.

I'm getting the error from oracle: [Oracle][ODBC][Ora]ORA-00972: identifier is too long...

The code: PHP connection odbc with oracle

Table in DB
CREATE TABLE ARCHIVOS
(
  ID       NUMBER,
  ARCHIVO  BLOB,
  NOMBRE   VARCHAR2(150 BYTE),
  TIPO     VARCHAR2(150 BYTE)
);

The code: PHP connection odbc with oracle

<code>
<?php 
if(filter_input(INPUT_POST, 'btnGuardar')){
  $id=  filter_input(INPUT_POST, 'id');


  $archivo_nombre=$_FILES['archivo']['name'];
  $archivo_tipo = $_FILES['archivo']['type'];  
  $archivo_temp = $_FILES['archivo']['tmp_name']; 
  $archivo_string=  file_get_contents($archivo_temp);

  $user = "user ";
  $password = "password";
  $driver = "Oracle in OraClient11g_home1";
  $odbc_string = "DSN=INVENTARIOREPORTS;DRIVER= 
  {".$driver."};SERVER=127.0.0.1;DATABASE=DB;";

  $conn = odbc_connect($odbc_string,$user,$password);

  $sql = " INSERT INTO ARCHIVOS (ID, ARCHIVO, NOMBRE, TIPO) VALUES 
  (".$id.",".$archivo_string.",'".$archivo_nombre."','".$archivo_tipo."') ";

  $res = odbc_exec($conn,$sql);

  if ($res) {
    echo 'correcto';
  }else{
    echo 'Error al guardar';
  }

  odbc_close($conn);

  $res = null;
}
?>

<!--FORMULARIO-->
<!DOCTYPE html>
<html>
 <head>
   <meta charset="UTF-8">
   <title></title>
  </head>
 <body>
   <form method="post" action="" enctype="multipart/form-data">
     id <input type="number" name="id" /><br/>
     <input type="file" name="archivo" /><br/><br/>
     <input type="submit" name="btnGuardar" value="Guardar" />
   </form>
 </body>
</html>

</code>

I would also like to be able to access these files, can you help me please?enter image description here

  • 写回答

1条回答 默认 最新

  • dtoaillwk759656786 2018-10-11 14:19
    关注

    If you print $sql you'll see you have 3 string values but you only quote 2 of them.

    The proper way to avoid silly typos like this and SQL injection too is to use prepared statements:

    $sql = 'INSERT INTO ARCHIVOS (ID, ARCHIVO, NOMBRE, TIPO)
        VALUES(?, ?, ?, ?)';
    $stmt = odbc_prepare($conn, $sql);
    $success = odbc_execute($stmt, [$id, $archivo_string, $archivo_nombre, $archivo_tipo]);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测