How to get data from MySQL database and convert them to PHP ... open

How to get data from MySQL database and convert them to PHP array

Approved. Code works!
This is exactly the working code that is verified by the moderator or site administrators

For example, we get an array of posts from our test database:

//create a database connection
$conn = mysqli_connect('localhost', 'root', 'password', 'testdb');

//get data from the table of posts
$posts = mysqli_query($conn, "SELECT * FROM `posts`");

//convert the data into a php array using the function mysqli_fetch_all()
$posts = mysqli_fetch_all($posts);

Now on our data we have available operations that are available with the usual array:

foreach ($posts as $post) {
    echo $post[0]; 
}
0

More

Leave a Reply

Your email address will not be published. Required fields are marked *

How many?: 22 + 22

lil-code© | 2022 - 2024
Go Top
Authorization
*
*
Registration
*
*
*
*
Password generation