简体   繁体   中英

PHP ibase query

i want to use PHP for internet service in my IOS 7 application. I've tried to generate an code for receiving objects from a Firebird database. My Code bellow:

<?php
$host = 'xxx';
$username = 'xxx';
$password = 'xxx';
$conn = ibase_connect($host, $username, $password) or 
die ("Verbindung fehlgeschlagen");

$arr = array();
$data = array();
$stmt = "select * from xxx";
$sth = ibase_query($conn, $stmt);
while ($row = ibase_fetch_object ($sth)) {

    $data['ID'] = $row->ID;
    $data['VON'] = $row->VON;
    $data['AN'] = $row->AN;
    $data['BETREFF'] = $row->BETREFF;
    $data['DATUM'] = $row->DATUM;
    $data['KOMMISSIONSNR'] = $row->KOMMISSIONSNR;
    $data['NACHRICHT'] = $row->NACHRICHT;
    $data['GELESEN'] = $row->GELESEN;
    $data['GEANTWORTET'] = $row->GEANTWORTET;
    $data['STATUS'] = $row->STATUS;
    $data['AUFTRAG'] = $row->AUFTRAG;
 $arr[] = array($data);
}                       
echo json_encode($arr);
?>

By calling the code in Safari-browser no values or arrays be returned. If giving an Key like 1 ( echo json_encode($arr[1]); ) an array on the browser will be shown.

How can i show the whole array with all keys? I should add that i want to use the results from my ibase-query as NSDictionary in the application.

And which framework is the best for encoding the PHP-Array to IOS? I've tried to use JSONDictionaryExtensions, but don't know if it's the right for this Code.

i hope you can help me.

Sorry for my bad english.

I'm not sure why you are putting the $data array into another array. You can skip that step.

When you echo json_encode($data) you encode the array as JSON, so that is what your iOS application gets and what it needs to decode. Decoding JSON into an NSArray or NSDictionary has been asked many times here on StackOverflow, like this question .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM