我已經檢查了很多示例代碼,但仍在努力使礦山正常工作。我正嘗試從我的PHP腳本生成XML輸出。從PHP生成XML輸出
的login.php
<?php
mysql_connect("localhost", "root", "") or die("cannot connect");
mysql_select_db("ConquestOfLancaster") or die("cannot select DB");
$username = $_REQUEST['username'];
$password = sha1($_REQUEST['password']);
$username = mysql_real_escape_string($username);
$domDoc = new DOMDocument;
$rootElt = $domDoc->createElement('root');
$rootNode = $domDoc->appendChild($rootElt);
$sql = "SELECT user_id, user_name FROM tbl_user WHERE user_name='$username' and user_pass='$password'";
$result = mysql_query($sql);
$count=mysql_num_rows($result);
if($count > 0){
//echo("welcome");
$rootAtr = $domDoc->createAttribute('success');
$rootAtrVal = $domDoc->createTextNode('TRUE');
$rootAtr->AppendChild($rootAtrVal);
$rootElt->AppendChild($rootAtr);
$subElt = $domDoc->createElement('username');
$subNode = $rootNode->appendChild($subElt);
$textNode = $domDoc->createTextNode($username);
$subNode->appendChild($textNode);
echo htmlentities($domDoc->saveXML());
} else{
//echo("not exist");
$rootAtr = $domDoc->createAttribute('success');
$rootAtrVal = $domDoc->createTextNode('FALSE');
$rootAtr->AppendChild($rootAtrVal);
$rootElt->AppendChild($rootAtr);
echo htmlentities($domDoc->saveXML());
}
?>
和瀏覽器的輸出是
<?xml version="1.0"?> <root success="TRUE"><username>user1</username></root>
我的主要問題是,與此PHP交互我的iOS應用程序無法解析這個結果。我做錯了什麼?
,這是非常錯誤的第一件事就是用depricated mysql_ *命令集。使用PDO或mysqli –
這會改變XML生成的方式嗎?我的意思是從我這邊來看是一個重要的錯誤? – OutOfBoundsException
不會更改xml,但在新代碼中使用過時的不受支持的技術是個不錯的主意。 http://ca1.php.net/manual/en/function.mysql-connect.php –