{"id":7114,"date":"2022-03-18T15:19:11","date_gmt":"2022-03-18T06:19:11","guid":{"rendered":"https:\/\/www.auctionpro.co.kr\/?p=7114"},"modified":"2024-02-29T14:48:08","modified_gmt":"2024-02-29T05:48:08","slug":"php-echo-xml-%ed%98%95%ec%8b%9d%ec%9c%bc%eb%a1%9c-%ec%b6%9c%eb%a0%a5","status":"publish","type":"post","link":"https:\/\/www.auctionpro.co.kr\/?p=7114","title":{"rendered":"php echo xml \ud615\uc2dd\uc73c\ub85c \ucd9c\ub825"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Remark : \uc6f9\ud654\uba74\uc5d0 XML \ud615\uc2dd\uc73c\ub85c \ub098\uc624\uae30 \ud558\uae30 <\/h4>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:vim decode:true \" title=\"xml\" >&lt;?php\n\/\/ Database configuration\n$host     = \"localhost\";  \/\/ Your database host\n$username = \"username\";   \/\/ Your database username\n$password = \"password\";   \/\/ Your database password\n$dbname   = \"database\";   \/\/ Your database name\n$table    = \"table\";      \/\/ Your database table\n\n\/\/ Create a new connection to the MySQL database\n$mysqli = new mysqli($host, $username, $password, $dbname);\n\n\/\/ Check for any connection errors\nif ($mysqli-&gt;connect_error) {\n    die(\"Connection failed: \" . $mysqli-&gt;connect_error);\n}\n\n\/\/ SQL query to select data from the table\n$query = \"SELECT * FROM $table\";\n$result = $mysqli-&gt;query($query);\n\n\/\/ Check if there are any rows returned\nif ($result-&gt;num_rows &gt; 0) {\n    \/\/ Start XML file, echo parent node\n    echo \"&lt;?xml version='1.0' encoding='UTF-8'?&gt;\";\n    echo \"&lt;root&gt;\";\n\n    \/\/ Iterate through the rows in the result set\n    while($row = $result-&gt;fetch_assoc()) {\n        echo \"&lt;item&gt;\";\n        echo \"&lt;id&gt;\" . $row[\"id\"] . \"&lt;\/id&gt;\";\n        echo \"&lt;name&gt;\" . htmlspecialchars($row[\"name\"]) . \"&lt;\/name&gt;\";\n        \/\/ Add more fields as needed\n        echo \"&lt;\/item&gt;\";\n    }\n\n    echo \"&lt;\/root&gt;\";\n} else {\n    echo \"0 results\";\n}\n\n\/\/ Close the database connection\n$mysqli-&gt;close();\n?&gt;<\/pre><\/div>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:php decode:true \">header('Content-type: text\/xml'); \/\/xml type out\necho $return;<\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\uc18c\uc2a4\uc0c1\uc5d0 echo \ub0b4\uc6a9\uc5d0 \ub2e8\uc9c0 xml \ud615\uc2dd\ub9cc \uc788\uc5b4\uc57c \uc544\ub798\uc640 \uac19\uc774 \ucd9c\ub825.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2022\/03\/Soap_PHP.png\"><img loading=\"lazy\" decoding=\"async\" width=\"923\" height=\"633\" src=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2022\/03\/Soap_PHP.png\" alt=\"\" class=\"wp-image-7115\" srcset=\"https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2022\/03\/Soap_PHP.png 923w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2022\/03\/Soap_PHP-300x206.png 300w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2022\/03\/Soap_PHP-768x527.png 768w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2022\/03\/Soap_PHP-150x103.png 150w, https:\/\/www.auctionpro.co.kr\/wp-content\/uploads\/2022\/03\/Soap_PHP-400x274.png 400w\" sizes=\"auto, (max-width: 923px) 100vw, 923px\" \/><\/a><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Json \uc73c\ub85c \ucd9c\ub825<\/h3>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:vim decode:true \" title=\"Json\" >&lt;?php\n\/\/ Database configuration\n$host     = \"localhost\";  \/\/ Your database host\n$username = \"username\";   \/\/ Your database username\n$password = \"password\";   \/\/ Your database password\n$dbname   = \"database\";   \/\/ Your database name\n$table    = \"table\";      \/\/ Your database table\n\n\/\/ Create a connection to the MySQL database\n$mysqli = new mysqli($host, $username, $password, $dbname);\n\n\/\/ Check for any connection errors\nif ($mysqli-&gt;connect_error) {\n    die(\"Connection failed: \" . $mysqli-&gt;connect_error);\n}\n\n\/\/ SQL query to select data from the table\n$query = \"SELECT * FROM $table\";\n$result = $mysqli-&gt;query($query);\n\n$data = array();\nif ($result-&gt;num_rows &gt; 0) {\n    \/\/ Fetch each row in the result set\n    while($row = $result-&gt;fetch_assoc()) {\n        $data[] = $row;\n    }\n} else {\n    echo \"0 results\";\n}<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>Remark : \uc6f9\ud654\uba74\uc5d0 XML \ud615\uc2dd\uc73c\ub85c \ub098\uc624\uae30 \ud558\uae30 \uc18c\uc2a4\uc0c1\uc5d0 echo \ub0b4\uc6a9\uc5d0 \ub2e8\uc9c0 xml \ud615\uc2dd\ub9cc \uc788\uc5b4\uc57c \uc544\ub798\uc640 \uac19\uc774 \ucd9c\ub825. Json \uc73c\ub85c \ucd9c\ub825<\/p>\n<\/div>","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[43],"tags":[],"class_list":["post-7114","post","type-post","status-publish","format-standard","hentry","category-php"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/7114","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7114"}],"version-history":[{"count":0,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/7114\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7114"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.auctionpro.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}