i want in php how can do.
i not find library supports batch sql in php 1 of main reason of choosing orient db batch features php found nothing please help.
i have downloaded doctrine/odm antonterekhov_orientdb-php
github
i able run batch sql studio:-
let $u=select person id=1 let $f=select expand(out(friend)) $u[0] let $a=create vertex posts set created_by=$u[0],text="hello............lllll" let $pbedge=create edge posted_by $a $u let $swith=create edge shared_with $a $f commit return $a
after finding @ many places decided create own class / driver orient db. here git hub address
if needs free use............. able execute both batch , 1 liner statements/queries/sql of orientdb
<?php /******** © fun n enjoy internet ltd ( http://www.funnenjoy.com ) *********** * * /*********** author: ravinder payal ****************** * * /***************date / time :- 27 sept 2015 10:25 pm *****************/ class orientdb{ private $host,$username,$password; private $connection; function __construct($host,$username,$password){ if(empty($host)){ throw "host address not provide"; } if(empty($username) || empty($password)){ throw "provide username / password. receaved empty strings"; } $this->host=$host; $this->username=$username; $this->password=$password; } function connect(){ $this->connection=curl_init(); curl_setopt($this->connection, curlopt_userpwd, $this->username.":".$this->password); curl_setopt($this->connection, curlopt_returntransfer, 1); } function query($db,$query){ curl_setopt($this->connection, curlopt_url, $this->host."/batch/".$db); curl_setopt($this->connection, curlopt_customrequest, "post"); curl_setopt($this->connection, curlopt_post,1); $json='{ "transaction" : true,"operations" : [{"type" : "script","language" : "sql","script" : [ "'.$query.'" ]}]}'; curl_setopt($this->connection, curlopt_httpheader, array('content-type: application/json','connection: keep-alive','content-length: ' . strlen($json) )); curl_setopt($this->connection, curlopt_postfields, $json); $result=curl_exec($this->connection); $http_code=curl_getinfo($this->connection,curlinfo_http_code); if($http_code!=200){ if($http_code==0){ throw new exception("host not accessible."); } $result=json_decode($result); throw new exception("server returned ".$result->errors[0]->content." code ".$result->errors[0]->code); } $result=json_decode($result); return $result; } function close(){ curl_close($this->connection); } }
if have better answer ,i accept heart.
Comments
Post a Comment