Last active
August 15, 2025 19:49
-
-
Save thinkphp/61d794e27df9da57b91a21a14b48aa11 to your computer and use it in GitHub Desktop.
get_gallery.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| ini_set('display_errors', 1); | |
| ini_set('display_startup_errors', 1); | |
| error_reporting(E_ALL); | |
| $host = 'localhost'; | |
| $username = 'lizard'; | |
| $password = "adidas88"; | |
| $dbname = 'gallery_database'; | |
| $conn = new mysqli($host, $username, $password, $dbname); | |
| //check connection | |
| if($conn->connect_error) { | |
| http_response_code(500); | |
| echo json_encode(['error' => 'Databased connection failed: ' . $conn->connect_error]); | |
| exit; | |
| } | |
| //extragem datale din tabel | |
| $SQL = "SELECT id, filename, title, size, price, caption FROM gallery ORDER BY id"; | |
| $result = $conn->query( $SQL ); | |
| if( $result ) { | |
| $galleryData = []; | |
| while($row = $result->fetch_assoc()) { | |
| $galleryData[] = $row; | |
| } | |
| header('Content-Type: application/json'); | |
| echo json_encode($galleryData); | |
| } else { | |
| http_response_code(500); | |
| echo json_encode(['error' => 'Query failed:' . $conn->error]); | |
| } | |
| //inchidem conectiunea la baza de date | |
| $conn->close(); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment