My MySQL table looks like this:
and I want to retrieve the data from the column 'host' from where uid is equal to twenty.
I have some code that will connect to the database and will return the row when uid is equal to twenty
DB.php:
public function query($sql, $params = array()){
$this->_error = false;
if($this->_query = $this->_pdo->prepare($sql)){
$x = 1;
if(count($params)){
foreach($params as $param){
$this->_query->bindValue($x, $param);
$x++;
}
}
if($this->_query->execute()){
$this->_results = $this->_query->fetchAll(PDO::FETCH_OBJ);
$this->_count = $this->_query->rowCount();
} else {
$this->_error = true;
}
}
return $this;
}
public function results(){
return $this->_results;
}
server.php:
public static function get($uid){
$_db = DB::getInstance();
$data = $_db->get('servers', array('uid', '=', $uid));
return $data->results();
}
cURL.php:
$a = Server::get('20');
var_dump($a);
The var_dump on the return gives the following:
array(2) { [0]=> object(stdClass)#5 (4) { ["sid"]=> string(2) "13" ["host"]=> string(12) "example.home" ["port"]=> string(4) "8081" ["uid"]=> string(2) "20" } [1]=> object(stdClass)#6 (4) { ["sid"]=> string(3) "153" ["host"]=> string(15) "stream.as.ag.ca" ["port"]=> string(5) "23434" ["uid"]=> string(2) "20" } }
Note: If this question has already been answered somewhere else, could a link be provided as I couldn't find the answer.
I think you should be able to pull each host with this.
foreach($a as $row) {
echo $row->host;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.