[英]Do these functions check if there's a connection to the database and display the data?
有人可以解释这两个功能的作用吗? 我认为他们会检查您是否连接到数据库,并且如果没有显示错误,但我不确定。 我也不知道发生了什么事情。 有人可以解释一下吗?
<?php
private function getData($sqlQuery) {
$result = mysqli_query($this->dbConnect, $sqlQuery);
if(!$result){
die('Error in query: '. mysqli_error());
} //peforms a query against database to check it is connected
$data= array();
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$data[]=$row;
}
return $data;
}
private function getNumRows($sqlQuery) {
$result = mysqli_query($this->dbConnect, $sqlQuery);
if(!$result){
die('Error in query: '. mysqli_error());
}
$numRows = mysqli_num_rows($result);
return $numRows;
}
}
?>
<?php
private function getData($sqlQuery) { //creates a function named 'getData' with a required parameter
$result = mysqli_query($this->dbConnect, $sqlQuery); //uses mysqli to query against the "$dbConnect" resource using the passed parameter $sqlQuery
if(!$result){ //If the result doesn't exist die
die('Error in query: '. mysqli_error());//die and show error
} //peforms a query against database to check it is connected
$data= array();//create an empty array
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {//fetch a row using association (aka an array mapped by keys with no numbered index)
$data[]=$row;//array push the returned row
}
return $data;//return an array of arrays that you've gotten from MySqlI
}
private function getNumRows($sqlQuery) {//create a function
$result = mysqli_query($this->dbConnect, $sqlQuery);//query
if(!$result){//if no result die
die('Error in query: '. mysqli_error());//die and show error
}
$numRows = mysqli_num_rows($result);//get the number of rows in the query
return $numRows;//return the number of rows in the query
}
}
?>
希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.