php 獲取mysql數(shù)據(jù)庫信息代碼
更新時間:2009年03月12日 23:23:15 作者:
有時候我們需要知道m(xù)ysql數(shù)據(jù)庫中的一些情況,好在php提供了一些內(nèi)置方法與函數(shù),大家了解下了。
復制代碼 代碼如下:
<?php
@mysql_connect("localhost", "root","1981427") //選擇數(shù)據(jù)庫之前需要先連接數(shù)據(jù)庫服務器
or die("數(shù)據(jù)庫服務器連接失敗");
$dbs = mysql_list_dbs(); //調(diào)用mysql_list_dbs函數(shù)
while ($array = mysql_fetch_row($dbs)) //循環(huán)輸出所有的數(shù)據(jù)庫名稱
{
echo "$array[0]<BR>";
}
?>
復制代碼 代碼如下:
<?php
@mysql_connect("localhost", "root","1981427") //選擇數(shù)據(jù)庫之前需要先連接數(shù)據(jù)庫服務器
or die("數(shù)據(jù)庫服務器連接失敗");
$dbs = mysql_list_tables("test"); //調(diào)用mysql_list_tables函數(shù)
while ($array = mysql_fetch_row($dbs)) //循環(huán)輸出所有的表名稱
{
echo "$array[0]<BR>";
}
?>
復制代碼 代碼如下:
<?php
mysql_connect("localhost","root","1981427"); //連接服務器
mysql_select_db("test"); //選擇數(shù)據(jù)庫
$result = mysql_query("SELECT * FROM tablename1"); //執(zhí)行查詢操作
echo mysql_num_fields($result); //獲取列的數(shù)目
?>
復制代碼 代碼如下:
<?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); //獲取列的數(shù)據(jù)類型
?>
復制代碼 代碼如下:
<?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"); //選擇數(shù)據(jù)庫
echo "<table border='1'>"; //輸出表頭
echo "<tr><th>列名</th><th>類型</th><th>長度</th><th>標志</th>";
$result = mysql_query("SELECT * FROM tablename1"); //在mytable表上執(zhí)行SQL語句
$fields = mysql_num_fields($result); //獲得列的數(shù)目
for($i=0; $i<$fields; $i++) //循環(huán)獲得各列信息
{
//獲得列的各個屬性
$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(); //關閉與數(shù)據(jù)庫的連接
?>
您可能感興趣的文章:
相關文章

php獲得客戶端瀏覽器名稱及版本的方法(基于ECShop函數(shù))
這篇文章主要介紹了php獲得客戶端瀏覽器名稱及版本的方法,基于ECShop函數(shù)get_user_browser實現(xiàn)該功能,非常具有實用價值,需要的朋友可以參考下
2015-12-12