Home > Backend Development > PHP Tutorial > PHP code for reading fields in all mysql databases and tables

PHP code for reading fields in all mysql databases and tables

WBOY
Release: 2016-07-25 08:58:36
Original
1594 people have browsed it
This article introduces a piece of code that uses PHP to read the fields in all libraries and tables in the MySQL database. It is simple and easy to use. Friends in need can refer to it.

The code is as follows:

<?php
/**
* 读取Mysql数据库 表中字段
* edit bbs.it-home.org
*/
$link = mysql_connect('localhost','root','123456');
echo mysql_error();
echo "当前MYSQL版本:".mysql_get_server_info()."<br>";
$db = mysql_list_dbs($link);
while($row = mysql_fetch_object($db)){
  $db_name = $row->Database;
  echo "<b>数据库:".$db_name."</b>"."<br>";
  $db_table = mysql_list_tables($db_name);
  while($row = mysql_fetch_row($db_table)){
    $result = mysql_query("select * from $row[0]");
    $flags=mysql_field_flags($result,0);
    echo "<pre class="brush:php;toolbar:false">
    $row[0] :  $flags <br>
   
Copy after login
"; } } ?>

Interested friends can extend the above code to not only query the database and fields in the table, but also query the database version, table information, stored procedures, etc. It would be even better to write it as a class that can be called anywhere.



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template