Нужна помощь донатом
для написания учебников Kotlin, Java, C++, C#, Go, Rust, Dart
подробности по ссылке
⊗ppSpAiDb 48 of 83 menu
◀ ▶

API and Databases in PHP

Often, an API is used to retrieve data from a database. Let's look at an example.

Suppose we have a table with users. Let's create an API that will take a user's id as a parameter and return the data from the database for that user:

<?php $id = $_GET['id']; $query = "SELECT * FROM users WHERE id=$id"; $result = mysqli_query($link, $query); $user = mysqli_fetch_assoc($result); header('Content-Type: application/json'); echo json_encode($user, true); ?>

Suppose the database stores countries and their cities. Create an API that will take a country as a parameter and return an array of its cities.

← →
↑
English▼
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline