php中的批处理orientdb sql [英] batch orientdb sql in php
问题描述
我想在 php 中使用这个我该怎么做.
i want this in php how can i do.
我在 php 中没有找到任何支持批处理 sql 的库,我选择 orient db 的主要原因之一是它的批处理功能,但对于 php,我什么也没找到,请帮忙.
I does not find any library which supports batch sql in php my one of main reason of choosing orient db is its batch features but for php i found nothing please help.
我已经从 GitHub 下载了 doctrine/odm 以及 AntonTerekhov_OrientDB-PHP
I have downloaded doctrine/odm as well AntonTerekhov_OrientDB-PHP
from GitHub
我可以从工作室运行这个批处理 sql:-
I am able run this batch sql from studio:-
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
推荐答案
在找了很多地方后,我决定为 Orient DB 创建自己的类/驱动程序.这是Git Hub 地址
After finding at many places I decided to create my own Class / Driver for Orient DB. Here is Git Hub address
如果有人需要这个,你可以免费使用........可以同时执行orientDB的批处理和单行语句/查询/SQL
If someone needs this you are free to use............. It is able execute both batch and one 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 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);
}
}
如果有人有更好的答案,我会从心里接受.
If someone have better answer ,I will accept that from my heart.
这篇关于php中的批处理orientdb sql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!