//Establish connection by instantiated
$db = new mysqli(
$dbHost ,
$dbName,
$dbUsername,
$dbPassword
);
//Error
if ($db->connect_error){
die("Cannot connect to database: \n"
. $db->connect_error . "\n"
.$db->connect_errno
);
}
//Return the Object
return $db;
}
function fetchAll(mysqli $db){
//Return an array of data
$data = [];
$sql = 'SELECT * FROM city';
$results = $db->query($sql);
if (!$results) {
trigger_error('Invalid query: ' . $db->error);
}
//Loop
if ($results->num_rows > 0){
while($row = $results->fetch_assoc()){
$dat[] = $row;
}
}
return $data;
}
this is how to wrap
It looks like you posted long piece of code, consider editing it out and putting it on hastebin.com and pasting link to it instead. Alternatively, send your code in a file.
Обсуждают сегодня