以下PHP代码是使用SQLite3的DataTables.net服务器端处理的子集,总是会生成错误HttpGet request = new HttpGet("my URL");
response = httpClient.execute(request);
Unable to execute statement: datatype mismatch
有关DataTables.net服务器端处理的更多信息,请参阅 https://datatables.net/manual/server-side
答案 0 :(得分:0)
// Handle Server Side ajax request from DataTables in browser // init database $db = new SQLite3('appname.SQLite3.db'); // parse request parameters $start = (int) $_GET['start']; $length = (int) $_GET['length']; // Prepare statement $sql = " SELECT personId, personName FROM person LIMIT :start, :length "; $stmt = $db->prepare($sql); $stmt->bindParam(':start', $start); $stmt->bindParam(':length', $length); // execute statement $result = $stmt->execute(); $response['data'] = []; while ($row = $result->fetchArray(SQLITE3_NUM)) { $response['data'][] = $row; } // use same prepared statement to count not paged number of records $start = 0; $length = PHP_INT_MAX; $result = $stmt->execute(); // <---- fails here with datatype mismatch error ------- $recordsTotal = 0; while ($result->fetchArray(SQLITE3_NUM)) { $recordsTotal++; } $response['draw'] = (int) $_GET['draw']; // used by DataTables to synchronize request and reply $response['recordsTotal'] = $recordsTotal; header('Content-Type: application/json'); echo json_encode($rsp); exit;
将准备好的语句重置为执行前的状态。重置后,所有绑定都保持不变。
public bool SQLite3Stmt::reset ( void )