caspianweb online Ответов: 0

Как я могу сохранить выходные данные этого класса с помощью PHP в базах данных?


I can't save the output data of this class using php in databases

<pre lang="PHP"><pre><?php

    class api
    {
        public $apiAddress     = 'https://exaple.com/api-v2/';
        public $connectionMode = 'curl';
        public $outputType     = 'xml';
        public $token          = '';
        public $param          = [];
        public $response       = '';
        public $allMethod      = [
            'cityLoad'           => 'cityLoad',
            'hotelLoad'          => 'hotelLoad',
            
        ];

        public function __construct($token = false, $outputType = false, $connectionMode = false)
        {
            if (!$token) {
                $this->_error('token error!');
            }
            $this->token = $token;
            if ($outputType) {
                $this->outputType = (($outputType == 'xml' or $outputType == 'json' or $outputType == 'html') ? $outputType : $this->outputType);
            }
            if ($connectionMode) {
                $this->connectionMode = (($connectionMode == 'curl' or $connectionMode == 'file') ? $connectionMode : $this->connectionMode);
            }
        }

        public function action($method, $param = [])
        {
            switch ($method) {
                case 'getAllCities':
                    $this->_connection($this->allMethod['cityLoad']);
                    break;
                case 'getAllHotels':
                case 'getHotel':
                    $this->_connection($this->allMethod['hotelLoad'], $param);
                    break;
              
            }
            return $this->response;    }
        private function _connection($method = false, $param = [])
        {
            $action = $this->apiAddress . $this->token . '/' . $this->outputType . '/' . $method;
            if (!empty($param)) {
                $action .= '?' . http_build_query($param);
            }
            if ($this->connectionMode == 'curl') {
                $this->_curlConnection($action);
            } else {
                $this->_fileConnection($action);
            }    }
        private function _curlConnection($action)
        {
            $curl = curl_init();
            curl_setopt_array($curl, array(
                CURLOPT_RETURNTRANSFER => 1,
                CURLOPT_URL            => $action
            ));
            $this->response = curl_exec($curl);
            curl_close($curl);
        }
		
        private function _fileConnection($action)
        {
            $this->response = file_get_contents($action);
        }
        private function _error($message)
        {
            echo $message;
            exit;
        }
    }
    $myToken = 'f790000000000024';
    $xmlWithCurl = new api($myToken, 'xml', 'curl');
    $getAllHotels = $xmlWithCurl->action('getAllHotels', ['city' => 'London']);

?>


Что я уже пробовал:

down vote
favorite

    I can't save the output data of this class using php in databases gethotelclass.php

I want to store data such as hotel names, latitude and longitude using php in databases.

Richard MacCutchan

Где находится код, который выполняет обработку базы данных?

0 Ответов