This is a backup of all tables in the specified database into a SQL file, which can be downloaded. This source code comes from the dedecms program. It has many functions and is very practical, but the quality of the code needs to be improved
<ol class="dp-c"> <li class="alt"><span><span><!?php </span></span></li><li><span> </span></li><li class="alt"><span class="comment">/** **** Backup database structure ******/</span><span> </span></li><li><span> 🎜></span></li> Function name: table2sql() <li class="alt"> <span></span><span class="comment"></span></li> Function function: Convert the table structure into SQL <li> <span><span class="comment"></span></span></li> Function parameters: $table: table name to be extracted <li class="alt"> <span><span class="comment"></span></span></li> Return value: Return the extracted result, SQL collection <li> <span><span class="comment"></span></span></li> Function author: heiyeluren <li class="alt"> <span><span class="comment"></span></span></li> */<li><span> <span class="comment"></span></span></li><li class="alt"> <span><span class="comment"></span><span> </span></span>function</li><li> table2sql(<span></span>$table </li><li class="alt">) 🎜 >$db<span></span>; <span class="keyword"></span><span></span> ; "<span class="vars"></span>; <span></span></li><li> -->query(<span></span>"SHOW CREATE TABLE $table"</span></span></li> <li class="alt">); <span></span><span class="keyword"></span> <span> = </span><span class="vars">$db</span><span>->fetch_row(</span> </li>$createtable<li> <span>); </span><span class="vars"></span><span> "</span><span class="string">; </span><span></span> </li> ><li class="alt"> <span></span> }</li> <li><span> </span></li> <li class="alt"><span></span></li> <li> Function: Convert the table structure and data into SQL <span> </span><span class="comment"></span><span></span> Function parameters: $table : Table name to be extracted </li> <li class="alt"> <span></span><span class="comment"></span> Return value: Return the extracted result, SQL collection </li> <li> <span><span class="comment"></span></span> Function author: heiyeluren </li> <li class="alt"> <span><span class="comment"></span></span> </li> <li>function<span><span class="comment"> data2sql(</span></span>$table</li> <li class="alt">) <span><span class="comment"></span></span> { 🎜></li> <li><span>global<span class="comment"></span> </span></li>$db<li class="alt"><span>; <span class="comment"></span><span></span> </span></li>$tabledump<li> <span> = </span><span class="keyword">"DROP TABLE IF EXISTS $table; "</span><span>; </span><span class="vars"></span><span> >query(</span> </li>"SHOW CREATE TABLE $table"<li class="alt"><span>); </span></li> <li> <span> > = </span><span class="keyword">$db</span><span>->fetch_row(</span><span class="vars">$createtable</span><span>); 🎜></span>$tabledump</li> <li class="alt"> .= <span></span>$create<span class="vars"></span>[1].<span></span>"; "<span class="string"></span>; <span></span> </li> <li> <span></span><span class="vars"></span> <span>$db</span><span class="vars">->query(</span><span>"SELECT * FROM $table"</span><span class="string">); 🎜></span>$numfields<span></span> = </li> <li class="alt">$db<span></span>->num_fields(<span class="vars"></span>$rows<span></span>); <span class="vars"></span><span></span> <span class="vars"></span>$numrows<span></span> = </li> <li>$db<span></span>->num_rows(<span class="vars"></span>$rows<span></span>); <span class="vars"></span><span></span> > = <span class="string"></span>$db<span></span>->fetch_row(</li> <li class="alt">$rows<span></span>)) </li> <li> <span></span> <span class="vars"></span>$comma<span></span> = <span class="vars"></span>""<span></span>; <span class="string"></span><span></span> </li> <li class="alt">$tabledump<span></span> .= <span class="vars"></span>"INSERT INTO $table VALUES("<span></span>; <span class="vars"></span><span><p align="left"></p> <div style="display:none;"> <span id="url" itemprop="url">http://www.bkjia.com/PHPjc/486044.html</span><span id="indexUrl" itemprop="indexUrl">www.bkjia.com</span><span id="isOriginal" itemprop="isOriginal">true</span><span id="isBasedOnUrl" itemprop="isBasedOnUrl">http: //www.bkjia.com/PHPjc/486044.html</span><span id="genre" itemprop="genre">TechArticle</span><span id="description" itemprop="description">This is a backup of all tables in the specified database into a SQL file, which can be downloaded. This source code comes from the dedecms program. It has many functions and is very practical, but the quality of the code needs to be improved...</span> </div> <div class="art_confoot"></div></span> </li> </ol>