簡體   English   中英

這些功能是否檢查到數據庫的連接並顯示數據?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM