php 获取mysql数据库信息代码

yipeiwu_com6年前Mysql基础
复制代码 代码如下:

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

复制代码 代码如下:

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

复制代码 代码如下:

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

复制代码 代码如下:

<?php
mysql_connect("localhost","root","1981427");
mysql_select_db("test");
$result = mysql_query("SELECT * FROM tablename1");
echo mysql_field_name($result,0); //获取列的名称
?>

复制代码 代码如下:

<?php
mysql_connect("localhost","root","1981427");
mysql_select_db("test");
$result = mysql_query("SELECT * FROM tablename1");
echo mysql_field_type($result,0); //获取列的数据类型
?>

复制代码 代码如下:

<?php
mysql_connect("localhost","root","1981427");
mysql_select_db("test");
$result = mysql_query("SELECT * FROM tablename1");
echo mysql_field_len($result,0); //获取列的长度
?>

复制代码 代码如下:

<?php
mysql_connect("localhost","root","1981427");
mysql_select_db("test");
$result = mysql_query("SELECT * FROM tablename1");
echo mysql_field_flag($result,0); //获取列的标志
?>

复制代码 代码如下:

<?php
mysql_connect("localhost","root","1981427"); //连接服务器
mysql_select_db("test"); //选择数据库
echo "<table border='1'>"; //输出表头
echo "<tr><th>列名</th><th>类型</th><th>长度</th><th>标志</th>";
$result = mysql_query("SELECT * FROM tablename1"); //在mytable表上执行SQL语句
$fields = mysql_num_fields($result); //获得列的数目
for($i=0; $i<$fields; $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 "<tr><td>$name</td>
<td>$type</td>
<td>$length</td>
<td>$flags</td></tr>";
//输出列的信息
}
echo "</table>";
mysql_close(); //关闭与数据库的连接
?>

相关文章

php和mysql中uft-8中文编码乱码的几种解决办法

PHP页面转UTF-8编码问题 1.在代码开始出加入一行: 复制代码 代码如下: header("Content-Type: text/html;charset=utf-8"); 2....

解决PHP在DOS命令行下却无法链接MySQL的技术笔记

正好今天朋友 xjb 也碰到了这个问题,所以写了这篇笔记,将此问题的描述以及解决记录下。 问题描述:用 web 方式, 可以链接 mysql, 但是在命令行下, 却提示:   Fatal...

php查询mysql数据库并将结果保存到数组的方法

本文实例讲述了php查询mysql数据库并将结果保存到数组的方法。分享给大家供大家参考。具体分析如下: 这里主要用到了mysql_fetch_assoc函数 mysql_fetch_as...

php下将图片以二进制存入mysql数据库中并显示的实现代码

//保存图片到数据库的php代码 复制代码 代码如下: If($Picture != "none") { $PSize = filesize($Picture); $mysqlPictu...

php获取mysql版本的几种方法小结

select VERSION()  当前$res=mysql_query("select VERSION()");$row=mysql_fetch_row(...