我有一个数据库,我最近从MySQL转换为SQLite。我有一个PHP脚本,它从POST或GET请求中获取一个字符串,并查找该字符串并返回该行中的值。
<?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;
?>
这就是我现在使用的。有人可以帮我把它转换成iPhone上的SQLite。
此代码不起作用。
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);
}
它没有通过if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
答案 0 :(得分:0)
尝试使用sqlite3_errmsg(sqlite3 *)获取描述错误的英文文本。 我建议你使用FMDB(这是SQLite C API的obective-C包装器)。