0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

PHP: CouchDB のデータを作成 (Create)

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

fputs (STDERR,"*** 開始 ***\n");

Requests::register_autoloader();

$headers = array('Content-Type' => 'application/json');
$url_base = 'http://localhost:5984/nagano';

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

$result = Requests::put($url_base,$headers,"{}");

$dict_aa=data_prepare_proc ();

foreach ($dict_aa as $key => $value)
	{
	$str_json = json_encode ($value);

	print $str_json . "\n";

	$url = $url_base . "/" . $key;

	$result = Requests::put($url,$headers,$str_json);
	}

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

// ------------------------------------------------------------------
function data_prepare_proc ()
{
	$dict_aa = array ();

$dict_aa = dict_append_proc ($dict_aa,'t2021','長野',18945,'2002-3-12');
$dict_aa = dict_append_proc ($dict_aa,'t2022','松本',69537,'2002-10-7');
$dict_aa = dict_append_proc ($dict_aa,'t2023','上田',72186,'2002-9-15');
$dict_aa = dict_append_proc ($dict_aa,'t2024','小諸',49672,'2002-5-22');
$dict_aa = dict_append_proc ($dict_aa,'t2025','岡谷',82341,'2002-11-11');
$dict_aa = dict_append_proc ($dict_aa,'t2026','塩尻',32597,'2002-9-21');
$dict_aa = dict_append_proc ($dict_aa,'t2027','茅野',42519,'2002-8-24');
$dict_aa = dict_append_proc ($dict_aa,'t2028','飯田',52986,'2002-9-28');
$dict_aa = dict_append_proc ($dict_aa,'t2029','中野',72513,'2002-8-5');
$dict_aa = dict_append_proc ($dict_aa,'t2030','諏訪',58146,'2002-6-17');
$dict_aa = dict_append_proc ($dict_aa,'t2031','駒ヶ根',25371,'2002-8-15');
$dict_aa = dict_append_proc ($dict_aa,'t2032','佐久',78529,'2002-4-14');
$dict_aa = dict_append_proc ($dict_aa,'t2033','伊那',29416,'2002-7-21');
$dict_aa = dict_append_proc ($dict_aa,'t2034','千曲',81729,'2002-6-19');


	return $dict_aa;
}

// ------------------------------------------------------------------
function dict_append_proc ($dict_aa,$id,$name,$population,$date_mod)
{
	$dict_unit = array ();
	$dict_unit['name'] = $name;
	$dict_unit['population'] = $population;
	$dict_unit['date_mod'] = $date_mod;
	$dict_aa[(string)$id]= $dict_unit;

	return	$dict_aa;
}
// ------------------------------------------------------------------

実行

./couch_create.php
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?