1 回答
![?](http://img1.sycdn.imooc.com/5458657e000125a302200220-100-100.jpg)
TA贡献1831条经验 获得超9个赞
<?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
}
}
?>
希望这可以帮助
- 1 回答
- 0 关注
- 149 浏览
添加回答
举报