Source: medium.com

PHP backend with flutter

Category: PHP, MySQL

Hey guys on this article I am going to show you the step by step process that will enable you to connect your flutter app to a web server! Let’s agree that the first step, to connect to a web server is to have a web server :D, well if you have your own server already, thats good configure the webserver

Select the database you just created and then hit new to create a new table on your database user the above attributes on the table that you are going to create, and finally insert some dummy values into the table, those values are the ones that we will retrieve from our flutter app.

To do that we will need to create a file that is going to handle the connection with the server.page you will create two files, one called db.php and the other called get.php, now select the file db.php, and edit its contents, the code will look like this: Make sure to enter the correct credentials, or else you will get an error, from the home page, go to the manage databases window to get the correct credentials like database name and user name! db = new PDO ($dns, $user, $pass); will create a PDO object and will establish the db connection, in case there is an error it will be thrown to the catch block now select the get.php file, and edit its contents, the code is: here we first require the db.php file, to establish connection with our databse, the we create a variable $query that is going to query our database table, then we use the PDO command $stm = $db->prepare($query) to make sure that our query is error free, and finally we user $stm->execute(); to execute the query, then $row = $stm->fetch(PDO::FETCH_ASSOC); will assign to the variable row the content of the table in the form of an associative array, echo json_encode($row); will display the response in the json format.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners