PHP sql_php tutorial for creating SQLite by using the (PDO) MySQL table field one click

Source: Internet
Author: User
Starting from: http://www.zzzzy.com/201406053158.html

1     /**2 * MySQL table field One-click Generate SQL to create SQLite3 * $DB Database4 * $tbname table name5 * $is _blob need to save the image binary array ("IMG1", "Img2", "img3") Form, default to False6 * $retbname custom generated SQLite table name7 * Statement form for return SQL8      */9      Ten      Public functionCreat_sqlite ($db,$tbname,$is _blob=false,$retbname=false){ One          A         $runsql 1=$db->query ("Select * from"$tbname' Limit 1 '); -         $fields _rows=$runsql 1-ColumnCount (); -          the         $TB _fields_info=Array(); -         $TB _string= ""; -         $dot= ""; -          +          for($i= 0;$i<$fields _rows;$i++) {   -             if($i= = 1) { +                 $dot= ", "; A             } at              -             $TB _meta=$runsql 1->getcolumnmeta ($i); -             $TB _string.=$dot.$TB _meta[' Name ']; -             //var_dump ($TB _meta); -              - //If there is data and the field exists in a field that needs to be canceled in             if($is _blob&&In_array($TB _meta[' Name '],$is _blob)) { -                 $TB _string.= " "." Blob; to}Else { +                 //If you do not need to save as a binary -                 Switch($TB _meta[' Native_type ']){ the                      Case"Var_string": *                         $TB _string.= " "." varchar; $                          Break;Panax Notoginseng                          -                      Case"LONG": the                         $TB _string.= " "." Integer; +                          Break;  A                          the                      Case"BLOB": +                         $TB _string.= " "." Text; -                          Break; $                      Case"TINY": $                         $TB _string.= " "." smallint; -                          Break; -                 } the             } -             Wuyi             if(isset($TB _meta[' Flags '] [1]) && ($TB _meta[' Flags '] [1] = = = "Primary_key")) { the                 $TB _string.= " "." PRIMARY KEY "; -             } Wu              -             if(isset($TB _meta[' Flags '] [0]) && ($TB _meta[' Flags '] [0] = = = "Not_null")) { About                 $TB _string.= " "." Not NULL "; $             }     -  -             //var_dump ($TB _meta); -         } A  +         //the generated SQLite table name the         $retbname=$retbname==true?$retbname:$tbname; -          $         //SQL statement to create data the         $creat _data= "CREATE TABLE IF not EXISTS {$retbname} ($TB _string);";  the                 the         return $creat _data;  the}

http://www.bkjia.com/PHPjc/780020.html www.bkjia.com true http://www.bkjia.com/PHPjc/780020.html techarticle starting from: http://www.zzzzy.com/201406053158.html 1/* * 2 * mysql table field one-key generation create SQLite SQL 3 * $DB database 4 * $tbname table name 5 * $is _blob Need to save the picture in binary ...

  • 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.