Mysql
 sql >> Base de données >  >> RDS >> Mysql

Obtenir des données de Mysql et les convertir en tableau PHP

Vous pouvez utiliser mysqli_fetch_all()

    mixed mysqli_result::fetch_all ([ int $resulttype = MYSQLI_NUM ] )

ou

    mixed mysqli_fetch_all ( mysqli_result $result [, int $resulttype = MYSQLI_NUM ] )

pour référence lire http://php.net/manual/en/ mysqli-result.fetch-all.php

il y a aussi

<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$query = "SELECT Name, CountryCode FROM City ORDER by ID LIMIT 3";
$result = $mysqli->query($query);

while($row = $result->fetch_array())
{
$rows[] = $row;
}

foreach($rows as $row)
{
echo $row['CountryCode'];
}

/* free result set */
$result->close();

/* close connection */
$mysqli->close();
?>