sqlite - Clearing bindings on an SQLite3 statement doesn't seem to work (PHP) -


when inserting multiple rows sqlite3 in php using prepared statement, if don't bind parameter row value previous row inserted, if "clear" statement between lines.

look @ following example:

$db = new sqlite3('dogsdb.sqlite');  //create database $db->exec("create table dogs (id integer primary key, breed text, name text, age integer)");      $sth = $db->prepare("insert dogs (breed, name, age)  values (:breed,:name,:age)");  $sth->bindvalue(':breed', 'canis', sqlite3_text); $sth->bindvalue(':name', 'jack', sqlite3_text); $sth->bindvalue(':age', 7, sqlite3_integer); $sth->execute();  $sth->clear(); //this supposed clear bindings! $sth->reset();  $sth->bindvalue(':breed', 'russel', sqlite3_text);          $sth->bindvalue(':age', 3, sqlite3_integer); $sth->execute(); 

even though expect second line have null value 'name' column, value 'jack' instead!

so either 'clear' doesn't seem work (although returns true) or haven't understood it's supposed do.

how can clear bindings between inserts in sqlite3 (or pdo)? what's best way insert multiple rows rows might have null values fields?

#include <sqlite3.h> #include <stdio.h>  int main(void) {      sqlite3 *db;     char *err_msg = 0;     sqlite3_stmt *res;     sqlite3_stmt *res1;     int rc = sqlite3_open("test.sqlite", &db);      if (rc != sqlite_ok) {          fprintf(stderr, "cannot open database: %s\n", sqlite3_errmsg(db));         sqlite3_close(db);          return 1;     }      char *sql = "create table dogs (id integer primary key, breed text, name text, age text)";     rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);     if (rc == sqlite_ok) {         rc = sqlite3_step(res);      }     sqlite3_finalize(res);      char *sql1 = "insert dogs (breed, name, age)  values (:breed,:name,:age);";      rc = sqlite3_prepare_v2(db, sql1, -1, &res1, 0);       if (rc == sqlite_ok) {         printf("%d\n", sqlite3_bind_text(res1, 1, "breed1", 6, sqlite_static));         sqlite3_bind_text(res1, 2, "name1", 5, sqlite_static);         sqlite3_bind_text(res1, 3, "age1", 4, sqlite_static);         printf("%d\n", sqlite3_step(res1));     } else {          fprintf(stderr, "failed execute statement: %s\n", sqlite3_errmsg(db));     }     sqlite3_reset(res1);     sqlite3_clear_bindings(res1);     printf("%d\n", sqlite3_bind_text(res1, 2, "name2", 5, sqlite_static));     printf("%d\n", sqlite3_bind_text(res1, 3, "age2", 4, sqlite_static));      printf("%d\n", sqlite3_step(res1));       sqlite3_finalize(res1);     sqlite3_close(db);      return 0; } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -