Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- countries.xml
- <?xml version="1.0"?>
- <countries>
- <country>
- <code>IN</code>
- <name>India</name>
- </country>
- <country>
- <code>ID</code>
- <name>Indonesia</name>
- </country>
- </countries>
- Lengkapi program PHP di bawah ini.
- getcountries.php
- <?php
- // Membuka koneksi
- $servername = "dbserver";
- $username = "dbuser";
- $password = "dbpass";
- $dbname = "world";
- $conn = new mysqli($servername, $username, $password);
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- // Menyiapkan statement dan mengisi dengan input
- $stmt = $conn->prepare("SELECT FROM country WHERE "); // Lengkapi SQL dengan kondisi nama negara menggunakan LIKE
- $stmt->bind_param("s", "%".$_GET["name"]."%");
- // Menjalankan statement dan mengambil data negara
- $stmt->execute();
- $result = $stmt->get_result();
- // Menambahkan header untuk output XML
- header("Content-Type: text/xml");
- // Menulis XML dari semua data negara yang diambil
- echo // Lengkapi! (XML declaration)
- echo // Lengkapi! (root element opening tag)
- while ($row = $result->fetch_assoc()) {
- // Lengkapi!
- }
- echo // Lengkapi! (root element closing tag)
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement