PHP uses the PDO method to convert Mysql data to a function in the SQLite form. Recently, a function is used to convert mysql data to sqlite data, because we want to save the image data in blob binary format, I will write a class myself. from the class, I will extract this method to share it. In order to continue working normally in the future, I used the PDO method for processing.
/*** Create SQlite * $ db database * $ tbname table name * $ is_images the binary array of images to be saved through Mysql ("img1", "img2", "img3 ") format. the default value is false * return SQL's array format */function creat_sqlite ($ db, $ tbname, $ is_images = false) {$ runsql1 = $ db-> query ("SELECT * FROM '$ tbname' limit 1"); $ fields_rows = $ runsql1-> columnCount (); $ tb_fields_info = array (); $ tb_string = ""; for ($ I = 0; $ I <$ fields_rows; $ I ++) {$ dot = ($ I> 0 )? ",": ""; $ Tb_meta = $ runsql1-> getColumnMeta ($ I ); // if ($ is_images & in_array ($ tb_meta ['name'], $ is_images) {continue;} $ tb_string. = $ dot. $ tb_meta ['name']; switch ($ tb_meta ['native _ type']) {case "VAR_STRING": $ tb_string. = "". "varchar"; break; case "LONG": $ tb_string. = "". "integer"; break; case "BLOB": $ tb_string. = "". "text"; break;} if (isset ($ tb_meta ['flags'] [1]) & ($ Tb_meta ['flags'] [1] === "primary_key") {$ tb_string. = "". "primary key";} if ($ tb_meta ['flags'] [0] === "not_null") {$ tb_string. = "". "not null" ;}}// SQL statement for data creation $ creat_tbs ['data'] = "CREATE TABLE IF NOT EXISTS data ($ tb_string );"; // if ($ is_images) {$ tb_images = ''; foreach ($ is_images as $ k => $ v) {$ di = ($ k> 0 )? ",": ""; $ Tb_images. = $ di. $ v. "blob not null";} $ creat_tbs ['images'] = "create table if not exists images (id integer primary key not null, tid integer not null, $ tb_images ); ";}return $ creat_tbs ;}
The result (image not set) generated by the demo is (I converted it to the json format ):
|
{"Data": "create table if not exists data (id integer primary key not null, name varchar not null, nickname varchar not null, emails varchar not null, passwd varchar not null, status not null );"} |