开发者

How do I access something from a SQLite database on an iPhone?

开发者 https://www.devze.com 2023-01-15 09:17 出处:网络
I have a database that I recently converted from MySQL to SQLite. I have a PHP script that gets a string from a POST or GET Request and looks for that string and returns a value in that row.

I have a database that I recently converted from MySQL to SQLite. I have a PHP script that gets a string from a POST or GET Request and looks for that string and returns a value in that row.

<?php
require_once('../config.php');

$开发者_运维百科newNumber = $_REQUEST['new'] ;

$tbl_name = 'roomNumbers';

$sql="SELECT * FROM $tbl_name WHERE new='$newNumber'";

$result=mysql_query($sql) or die ('Error, cannot execute query');

    $data = mysql_query($sql);
    $info = mysql_fetch_array( $data );
    $oldNumber = $info['old'];

if($oldNumber == null) {$oldNumber = "Room Not Found";}
    echo $oldNumber;

?>

That is what I use now. Can someone help me convert it into SQLite on the iPhone.

This code doesn't work.

if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
        NSLog(@"entered readRoomsFromDatabase if 1");
        // Setup the SQL Statement and compile it for faster access
        const char *sqlStatement = "SELECT * FROM 'roomNumbers' WHERE new='h13'";


        sqlite3_stmt *compiledStatement;

        if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
                    NSLog(@"entered readRoomsFromDatabase if 2");
            if(sqlite3_step(compiledStatement) == SQLITE_ROW) {
                        NSLog(@"entered readRoomsFromDatabase if 3");

                NSString *aName =[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)];

                NSLog(aName);

            }
        }
        // Release the compiled statement from memory
        sqlite3_finalize(compiledStatement);

    }

It doesn't get passed the if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {


Try using sqlite3_errmsg(sqlite3*) to get English-language text that describes the error. And I'd suggest you to use FMDB (which is obective-C wrapper for SQLite C API).

0

精彩评论

暂无评论...
验证码 换一张
取 消