我想通過我正在開發的可可應用程序從我的MySql數據庫下載一系列行。我使用一個從我的應用程序接收索引的PHP,並將所有行都發送回該索引。 我的可可代碼:從可可應用程序獲取MySql數據庫 - PHP橋接
NSInteger index = 0;
NSString *urlString = [NSString stringWithFormat:@"http://localhost/test.php?index=%d&", index];
NSArray *items = [NSArray arrayWithContentsOfURL:[NSURL URLWithString: urlString]];
NSLog(@"%@", [items description]);
當PHP收到GET
變量index
運行這段代碼:
$index = $_GET['index'];
$Keys = array(...);
mysql_connect($Host, $User, $Password) or die("Unable to connect to database");
mysql_select_db($Database) or die("Unable to select database");
$result = mysql_query("SELECT * FROM transactions where id > $index ORDER BY id");
$plist = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$plist .= "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n";
$plist .= "<plist version=\"1.0\">\n";
$plist .= "<array>\n";
while($row = mysql_fetch_array($result)) {
$plist .= "\t<dict>\n";
foreach($Keys as $key){
$plist .= "\t\t<key>$key</key>\n";
$plist .= "\t\t<string>$row[$key]</string>\n";
}
$plist .= "\t</dict>\n";
}
$plist .= "</array>\n";
$plist .= "</plist>";
echo $plist;
unset($_GET['index']);
如果有多達來自index
30行,最後ID這一切工作正常的數據庫!如果從我的可可代碼中,我設置了index
來請求多達30行或者我將index
設置爲零(以請求所有數據庫)... NSArray
對象不包含任何內容!
我在做什麼錯?
感謝您的建議! – BitDrink 2009-07-28 11:20:25