首頁 >php教程 >php手册 >tp5 r3 一个简单的SQL语句调试实例

tp5 r3 一个简单的SQL语句调试实例

WBOY
WBOY原創
2016-06-07 11:34:411089瀏覽

tp5 r3 一个简单的SQL语句调试实例
先看效果
tp5 r3 一个简单的SQL语句调试实例
核心代码    public function index()<br>     {<br>         if (IS_AJAX && session("uid")==1){<br>             $sql=input("post.sql");<br>             $sql=base64_decode($sql);<br>             if ($sql){<br>                 if (preg_match('/INSERT INTO|DELETE|UPDATE\s/i', $sql, $info)){<br>                     $result=\think\Db::execute($sql);<br>                 }<br>                 else{                    <br>                     $result=\think\Db::query($sql);<br>                 }<br>                 return dump($result);//json_encode($result)<br>             }else{<br>                 return  "错误的sql语句"; <br>             }<br>             <br>         }<br>         //读取所有的表<br>         $tables=\think\Db::query('SHOW TABLES');<br>         $this->assign('tables',$tables);<br>         $database=\think\Config::get("database");<br>         $this->assign('tkey',"tables_in_".$database["database"]);<br>         return $this->fetch();<br>          <br>     }前台{include file="Public:header" /}<br> <div> <br>     <div> <br>         <div> <br>            <div> <br>                 <div><h2>数据库命令</h2></div> <br>                     <form> <br>                         <div> <br>                             <div> <br>                                 <br>                                 <div> <br>                                     <select><br>                                         {volist name="tables" id="vo"}<br>                                             <option>{$vo[$tkey]}</option> <br>                                         {/volist}<br>                                     </select><br>                                 </div> <br>                                 <div>                                     <br>                                     <a>快捷SQL语句<span></span></a><br>                                     <ul> <br>                                         <li> <i></i><strong>select语句</strong> </li> <br>                                         <li><a>select</a></li> <br>                                         <li><a>insert</a></li> <br>                                         <li><a>update</a></li> <br>                                         <li><a>delete</a></li>                                        <br>                                         <li>                                        <br>                                     </ul> <br>                                 </div> <br>                                 <br>                             </div> <br>                         </div> <br>                         <div> <br>                             <label>SQL命令语句</label><br>                             <div> <br>                                 <textarea></textarea><br>                             </div> <br>                         </div> <br>                         <div> <br>                             <div> <br>                                 <button>提交</button><br>                                 <button>重置</button><br>                             </div> <br>                         </div> <br>                     </form> <br>            </div> <br>         </div> <br>         <div> <br>             <div> <br>                 <div><h2>输出结果</h2></div> <br>                 <p></p> <br>            </div> <br>         </div> <br>     </div> <br>     <br> </div> <br> {include file="Public:footer" /}<br> <script></script><br> <script><br /> function insert($sql){<br /> if ($sql){<br /> var table=$("#tables").val();<br /> $("#sql").text($sql.replace("[table]", table));<br /> }<br /> }<br /> $("#form").click(function(){<br /> var sql=$("#sql").val();<br /> var url =$("#form-sql").attr("action");<br /> if (!sql){jError("SQL不能为空!!", {VerticalPosition: &#039;center&#039;,HorizontalPosition: &#039;center&#039;});return;}<br /> sql=base64_encode(sql);<br /> $.ajax({ <br /> url:url,<br /> data:{sql:sql}, <br /> type:&#039;post&#039;, <br /> cache:true, <br /> dataType:&#039;html&#039;, <br /> success:function(data) { <br /> $("#result").html(data); <br /> }, <br /> error : function() { <br /> $("#result").html(&#039;错误的SQL语句!<br/>&#039;+$("#sql").val());<br /> jError("错误的SQL语句!", {VerticalPosition: &#039;center&#039;,HorizontalPosition: &#039;center&#039;});<br /> } <br /> }); <br /> <br /> <br /> })<br /> </script>

AD:真正免费,域名+虚机+企业邮箱=0元

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn