tags:

views:

204

answers:

1

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) {

A: 

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).

eviltrue