如何在数据库中使用PHP保存此类的输出数据? [英] How can I save the output data of this class using PHP in databases?
本文介绍了如何在数据库中使用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']);
?>
我的尝试:
What I have tried:
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.
推荐答案
apiAddress ='https://exaple.com/api-v2/';
public
apiAddress = 'https://exaple.com/api-v2/'; public
connectionMode ='curl';
public
connectionMode = 'curl'; public
outputType ='xml';
public
outputType = 'xml'; public
这篇关于如何在数据库中使用PHP保存此类的输出数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文