2015-09-25 4 views
0

Я хочу это на php, как я могу это сделать.batch orientdb sql in php

Я не нашёл ни одной библиотеки, которая поддерживает пакетный sql в php. Одна из основных причин выбора orient db - его пакетные функции, но для php я ничего не нашел, помогите.

Я скачал doctrine/odm as well AntonTerekhov_OrientDB-PHP из GitHub

Я могу запустить эту партию SQL из студии: -

let $u=select from person where id=1 
let $f=select expand(out(Friend)) from $u[0] 
let $a=create vertex posts set created_by=$u[0],text="Hello............lllll" 
let $pbedge=create edge POSTED_BY from $a to $u 
let $swith=create edge shared_with from $a to $f 
commit 
return $a 

ответ

1

После нахождения во многих местах я решил создать свой собственный класс/драйвер для Orient БД. Вот Git Hub address

Если кто-то нуждается в этом вы можете использовать ............. Он способен выполнять как партии и один вкладыш заявления/запросы/SQL из 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 is not accessible."); 
           } 
       $result=json_decode($result); 
       throw new Exception("Server returned ".$result->errors[0]->content." With code ".$result->errors[0]->code); 
      } 
      $result=json_decode($result);   
      return $result; 

     } 
    function close(){ 
     curl_close($this->connection); 
     } 
} 

Если у кого-то есть лучший ответ, я буду принимать это от своего сердца.

+0

WDYT о внесении его в кодовую базу драйверов PHP? – Lvca

+0

yah sure мы будем счастливы ......... по вашему мнению, какие шаги мы должны следовать –

+1

@Lvca https://github.com/ravinderpayal/OrientDB-PHP добавлен в github –