To connect to the MySQL database:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
Making the Select in the database:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id, firstname, lastname FROM MyGuests";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>
In your case you can get the values returned and play directly:
$results = array((object) array(
'id' => $row["id"],
'nome' => $row["nome"],
'email' => $row["email"]
));
Without having your data to use for example it becomes difficult. But I believe that with this code you can connect to the database, make the select and mount the array.
UPDATE
To do in the loop with the select of the bank looks like this:
$newArray = array();
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$newArray[] = array(
'id' => $row["id"],
'nome' => $row["nome"],
'email' => $row["email"]
);
}
}
In the code above you put an array inside another one, maybe this is confusing you.
Look at this fiddler and see if it gets easier, in it I paste an object into the array. I believe it will be better in your case, but again, without your code to pick up and change it is difficult to understand what you really need.