您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

在PHP中批处理orientdb sql

在PHP中批处理orientdb sql

在很多地方找到之后,我决定为Orient DB创建自己的类/驱动程序。这是GitHub地址

如果有人需要,您可以自由使用.........它可以执行orientDB的批处理和一个内衬语句/查询/ sql

<?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);
        }   
}

如果有人有更好的答案,我会发自内心地接受。

php 2022/1/1 18:50:30 有314人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶