LoginSignup
0
0

More than 3 years have passed since last update.

PHP: CouchDB のデータを削除 (Delete)

Posted at
couch_delete.php
#! /usr/bin/php
<?php
// ------------------------------------------------------------------
//  couch_delete.php
//
//                      Jul/31/2020
//
// ------------------------------------------------------------------
include('Requests/library/Requests.php');

fputs (STDERR,"*** 開始 ***\n");
$key_in = $argv[1];
print   "key_in = " . $key_in . "\n";

Requests::register_autoloader();

$url_base = 'http://localhost:5984/nagano';
$url_target = $url_base . "/" . $key_in;

$request = Requests::get($url_target, array('Accept' => 'application/json'));

// var_dump($request->status_code);

$json_string = $request->body;
$data_aa = json_decode ($json_string,true);

// var_dump($data_aa);

if (array_key_exists ("_rev",$data_aa))
    {
    print($data_aa["_rev"] . "\n");
    print($data_aa["name"] . "\n");

    $url_del=$url_target . "?rev=" . $data_aa["_rev"];

    $result = Requests::delete($url_del);

    // var_dump($result);
    }
else
    {
    fputs (STDERR,"*** key doesn't exist ***\n");
    }

fputs (STDERR,"*** 終了 ***\n");

// ------------------------------------------------------------------

実行

./couch_delete.php t2024
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0