php获取当前数据库 php登录页面获取数据库字段

php mysql如何读取数据库数据?先配置数据库------连接数据库--------选择数据库--------填写检索表-------输出检索内容
第一种解决方法:
一、配置一下数据库:
define("DB_HOST","localhost");//数据库地址,一般为localhost
define("DB_USER","root");//数据库用户名
define("DB_PSW","");//数据库密码
define("DB_DB","databasename");//需要操作的数据库
二、连接数据库:
$conn = mysql_connect(DB_HOST,DB_USER,DB_PSW) or die
三、选择数据库:
mysql_select_db(DB_DB,$conn) or die
四、检索表:(填写tablename)
$result = mysql_query("select * from tablename") or die
五、输出检索的内容:
while ($row = mysql_fetch_row($result)){foreach($row as $data){echo $data.' ';}echo 'br 。
php如何获取数据库信息代码如下:?View
Code
PHP
include("conn.php");//调用数据库连接文件
echo
"table
width=572
height=56
cellspacing=1
";
//创建html表格
echo
"tr
bgcolor=#9999FF";
echo
"th
width=33
scope=colid/th";
echo
"th
width=100
scope=coluser_name/th
";
echo
"th
width=100
scope=coluser_pass/th
";
echo
"th
width=100
scope=colstaus/th";
echo
"th
width=100
scope=colinsert_time/th";
echo
"/tr";
$SQL
=
"select
*
from
user_info";
$query
=
mysql_query($SQL);
//SQL查询语句
while
($row
=
mysql_fetch_array($query)){
//使用while循环mysql_fetch_array()并将数据返回数组
echo
"tr
onmouseout=this.style.backgroundColor=''
onMouseOver=this.style.backgroundColor='#99CC33'
bgcolor=#CCCCCC";
echo
"td$row[0]/td";
//输出数组中数据
echo
"td$row[1]/td";
echo
"td$row[2]/td";
echo
"td$row[3]/td";
echo
"td$row[4]/td";
echo
"/tr";
}
echo
"/table";输出记录截图
如何正确理解PHP获取显示数据库数据函数1、PHP获取显示数据库数据函数之 mysql_result()
mixed mysql_result(resource result_set, int row [,mixed field])
从result_set 的指定row 中获取一个field 的数据. 简单但是效率低.
举例:
$link1 = @mysql_connect("server1",
"webuser", "password")
or die("Could not connect
to mysql server!");
@mysql_select_db("company")
or die("Could not select database!");
$query = "select id, name
from product order by name";
$result = mysql_query($query);
$id = mysql_result($result, 0, "id");
$name = mysql_result($result, 0, "name");
mysql_close();
注意,上述代码只是输出结果集中的第一条数据的字段值,如果要输出所有记录,需要循环处理.
for ($i = 0; $i = mysql_num_rows($result); $i)
{
$id = mysql_result($result, 0, "id");
$name = mysql_result($result, 0, "name");
echo "Product: $name ($id)";
}
注意,如果查询字段名是别名,则mysql_result中就使用别名.
2、PHP获取显示数据库数据函数之mysql_fetch_row()
array mysql_fetch_row(resource result_set)
从result_set中获取整行,把数据放入数组中.
举例(注意和list 的巧妙配合):
$query = "select id,
name from product order by name";
$result = mysql_query($query);
while(list($id, $name)
= mysql_fetch_row($result)) {
echo "Product: $name ($id)";
}
3、PHP获取显示数据库数据函数之mysql_fetch_array()
array mysql_fetch_array(resource result_set [,int result_type])
mysql_fetch_row()的增强版.
将result_set的每一行获取为一个关联数组或/和数值索引数组.
默认获取两种数组,result_type可以设置:
MYSQL_ASSOC:返回关联数组,字段名=字段值
MYSQL_NUM:返回数值索引数组.
MYSQL_BOTH:获取两种数组.因此每个字段可以按索引偏移引用,也可以按字段名引用.
举例:
$query = "select id,
name from product order by name";
$result = mysql_query($query);
while($row = mysql_fetch_array
($result, MYSQL_BOTH)) {
$name = $row['name'];
//或者 $name = $row[1];
$name = $row['id'];
//或者 $name = $row[0];
echo "Product: $name ($id)";
}
4、PHP获取显示数据库数据函数之mysql_fetch_assoc()
array mysql_fetch_assoc(resource result_set)
相当于 mysql_fetch_array($result, MYSQL_ASSOC)
5、PHP获取显示数据库数据函数之mysql_fetch_object()
object mysql_fetch_object(resource result_set)
和mysql_fetch_array()功能一样,不过返回的不是数组,而是一个对象.
举例:
$query = "select id, name
from product order by name";
$result = mysql_query($query);
while($row = mysql_fetch_object
($result)) {
$name = $row-name;
$name = $row-id;
echo "Product: $name ($id)";
}
以上这些函数就是PHP获取显示数据库数据函数的全部总结 。
如何用php获取数据库信息并显示获取ppq数据库的所有表名的代码:
?php
$server='localhost';
$user='root';
$pass='12345';
$dbname='ppq';
$conn=mysql_connect($server,$user,$pass);
if(!$conn)
die("数据库系统连接失败!");
$result=mysql_list_tables($dbname);
if(!$result)
die("数据库连接失败!");
while($row=mysql_fetch_row($result))
{
echo
$row[0]."
";
}
mysql_free_result($result);
?
mysql_list_tables
(PHP
3,
PHP
4
,
PHP
5)
mysql_list_tables
--
列出
MySQL
数据库中的表
说明
resource
mysql_list_tables
(
string
database
[,
resource
link_identifier])
mysql_list_tables()
接受一个数据库名并返回和
mysql_query()
函数很相似的一个结果指针 。用
mysql_fetch_array()或者用mysql_fetch_row()来获得一个数组,数组的第0列就是数组名 , 当获取不到时
mysql_fetch_array()或者用mysql_fetch_row()返回
FALSE 。
【php获取当前数据库 php登录页面获取数据库字段】php获取当前数据库的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于php登录页面获取数据库字段、php获取当前数据库的信息别忘了在本站进行查找喔 。

    推荐阅读