PHP SQLite addition, deletion, modification, and reduction implementation code _ PHP Tutorial

Source: Internet
Author: User
Added, deleted, modified, and subtracted implementation code for phpSQLite. Db.exe csql (SQL); or db. insert (), db. delete (), db. you can also create a table publicbooleancreatetable () {db.exe csql (SQL); or db through execsql. insert (), db. delete (), db. update (), including creating and deleting data tables, can also be implemented through execsql
// Create a table

Public boolean createtable (){
Sqlitedatabase db = dbhelper. getwritabledatabase ();
String SQL = "create table if not exists" + table_name + "(id integer primary key, name varchar, age integer )";
Try {
Db.exe csql (SQL );
Return true;
} Catch (sqlexception ex ){
Log. d (tag, "create table failure ");
Return false;
}
}

// Add data

Public boolean adddata (){
String name = etname. gettext (). tostring ();
String age = etage. gettext (). tostring ();
Sqlitedatabase db = dbhelper. getwritabledatabase ();
String SQL = "insert into" + table_name + "(name, age) values ('" + name + "', '" + age + "')";
Try {
Db.exe csql (SQL );
Return true;
} Catch (sqlexception ex ){
Log. d (tag, "add data failure ");
Return false;
}
}

// Modify

Public boolean updatedata (){
Sqlitedatabase db = dbhelper. getwritabledatabase ();
String SQL = "update" + table_name + "set age = '2' where name like 'cb '";
Object [] bindargs = {"cb "};
Try {
Db.exe csql (SQL, bindargs );
Return true;
} Catch (sqlexception ex ){
Log. d (tag, "update data failure ");
Return false;
}

}

Http://www.bkjia.com/PHPjc/630782.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/630782.htmlTechArticledb.execsql (SQL); or db. insert (), db. delete (), db. update (), including creating and deleting data tables, etc. you can also execsql to create a public boolean createtable (){...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.