php 获取mysql数据库信息代码_PHP

WBOY
Release: 2016-06-01 12:23:37
Original
1050 people have browsed it
复制代码 代码如下:
@mysql_connect("localhost", "root","1981427") //选择数据库之前需要先连接数据库服务器
or die("数据库服务器连接失败");
$dbs = mysql_list_dbs(); //调用mysql_list_dbs函数
while ($array = mysql_fetch_row($dbs)) //循环输出所有的数据库名称
{
echo "$array[0]
";
}
?>

复制代码 代码如下:
@mysql_connect("localhost", "root","1981427") //选择数据库之前需要先连接数据库服务器
or die("数据库服务器连接失败");
$dbs = mysql_list_tables("test"); //调用mysql_list_tables函数
while ($array = mysql_fetch_row($dbs)) //循环输出所有的表名称
{
echo "$array[0]
";
}
?>

复制代码 代码如下:
mysql_connect("localhost","root","1981427"); //连接服务器
mysql_select_db("test"); //选择数据库
$result = mysql_query("SELECT * FROM tablename1"); //执行查询操作
echo mysql_num_fields($result); //获取列的数目
?>

复制代码 代码如下:
mysql_connect("localhost","root","1981427");
mysql_select_db("test");
$result = mysql_query("SELECT * FROM tablename1");
echo mysql_field_name($result,0); //获取列的名称
?>

复制代码 代码如下:
mysql_connect("localhost","root","1981427");
mysql_select_db("test");
$result = mysql_query("SELECT * FROM tablename1");
echo mysql_field_type($result,0); //获取列的数据类型
?>

复制代码 代码如下:
mysql_connect("localhost","root","1981427");
mysql_select_db("test");
$result = mysql_query("SELECT * FROM tablename1");
echo mysql_field_len($result,0); //获取列的长度
?>

复制代码 代码如下:
mysql_connect("localhost","root","1981427");
mysql_select_db("test");
$result = mysql_query("SELECT * FROM tablename1");
echo mysql_field_flag($result,0); //获取列的标志
?>

复制代码 代码如下:
mysql_connect("localhost","root","1981427"); //连接服务器
mysql_select_db("test"); //选择数据库
echo ""; //输出表头
echo "";
$result = mysql_query("SELECT * FROM tablename1"); //在mytable表上执行SQL语句
$fields = mysql_num_fields($result); //获得列的数目
for($i=0; $i{
//获得列的各个属性
$name = mysql_field_name($result,$i); //获得列的名称
$type = mysql_field_type($result,$i); //获得列的类型
$length = mysql_field_len($result,$i); //获得列的长度
$flags = mysql_field_flags($result,$i); //获得列的标志
echo "


";
//输出列的信息
}
echo "
列名 类型 长度 标志
$name $type $length $flags
";
mysql_close(); //关闭与数据库的连接
?>
Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!