将json对象插入到oracle db表blob列中

问题描述 投票:0回答:1

以下内容在开发人员控制台中发布为POST:404。我猜我的php不正确。我在这里错了吗?

在这方面,我正在做:

    ........
    user = JSON.stringify(user); // updated Data, want to push to db table blob column
    pushData ();

    function pushData (){
        const ajax = $.ajax({
            method: 'POST',
            url: `./Settings.php`,
            data: {obj_json: JSON.stringify(user) },
            dataType: "json",
            success: function(result) {
                //Write your code here
                console.log("data posted?");
            }
          });
        }
  .....

( [Settings.php obj_json是在数据库表中设置为blob的列)。我不太确定该如何处理$obj

class Settingz extends \myApp\Data { public function insertBlob($obj, $last_update) { $obj = $_POST['obj_json']; $sql = "INSERT INTO MY_TABLE(last_update,obj_json) VALUES(:last_update,:obj_json)"; $stmt = $this->pdo->prepare($sql); $stmt->bindParam(':last_update', $last_update); $stmt->bindParam(':obj_json', $blob, PDO::PARAM_LOB); return $stmt->execute(); } }
php sql oracle post blob
1个回答
0
投票
<?php try { $db = new PDO('oci:dbname=localhost/orclpdb1', 'cj', 'welcome'); } catch (PDOException $e) { echo 'Connection failed: ' . $e->getMessage(); exit; } $stmt = $db->prepare("drop table cjblob"); $stmt->execute(); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $db->prepare("create table cjblob (id number, data blob)"); $stmt->execute(); function do_insert($db, $id, $data) { $stmt = $db->prepare("insert into cjblob (id, data) values (:id, empty_blob()) returning data into :blob"); $stmt->bindParam(':id', $id); $stmt->bindParam(':blob', $blob, PDO::PARAM_LOB); $blob = null; $db->beginTransaction(); $stmt->execute(); // var_dump($blob); // $blob becomes a stream fwrite($blob, $data); fclose($blob); $db->commit(); } do_insert($db, 1, str_pad("Z", 40000, "Z")); // Fetch it back $stmt = $db->prepare('select data from cjblob where id = ?'); $id = 1; $stmt->execute(array($id)); $row = $stmt->fetch(PDO::FETCH_ASSOC); var_dump($row); var_dump(stream_get_contents($row['DATA'])); ?>
© www.soinside.com 2019 - 2024. All rights reserved.