⑴ php如何查詢資料庫表中的數據並顯示
這個簡單啊!
首頁做個前台輸入姓名和會員卡信息的頁面,我做個簡單的頁面給你看
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""
<htmlxmlns="
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<title>會員查詢系統</title>
</head>
<body>
<formid="form1"name="form1"method="post"action="test.php">
<p>
<labelfor="name"></label>
<inputtype="text"name="name"id="name"/>
</p>
<p>
<labelfor="vipid"></label>
<inputtype="text"name="vipid"id="vipid"/>
</p>
<p>
<inputtype="submit"name="button"id="button"value="查詢"/>
</p>
</form>
</body>
</html>
然後我給你一個test.php的文件代碼:
<?php
$name=trim($_POST['name']);
$vipid=trim($_POST['vipid']);
$con=mysql_connect("127.0.0.1","資料庫用戶名","資料庫密碼");
if(!$con)
{
die('Couldnotconnect:'.mysql_error());
}
$a=mysql_select_db("資料庫名字",$con);
$sql="select*fromkh_customerwherename='$name'andvipid='$vipid'";
$result=mysql_query($sql);
while($row=mysql_fetch_array($result))
{
echo$row['name']."".$row['data'];
echo"<br/>";
}
mysql_close($con);
?>
⑵ php搜索查詢資料庫數據
查看一下代碼:
<?php
//獲取表單提交值
$student_id=intval(trim($_POST['student_id']));
//頁面表單可以放單獨的html文件中,如果放單獨的html頁面中form的action的地址要改成下面的PHP文件名
echo'<formaction=""method="post">
<inputtype="text"name="student_id"value="{$student_id}"/>
<inputtype="submit"name="submit"value="查詢"/>
</form>';
//當有數據提交時
if($student_id)
{
$con=mysql_connect("localhost","root","111")ordie("連接錯誤");
mysql_select_db("examination",$con);
//查詢
$sql="SELECT*FROMtablenameWHEREstudent_id=$student_id";
$res=mysql_query($sql);
$row=mysql_fetch_array($res);
//輸出
echo'學號:'.$row['student_id'].'<br>姓名:'.$row['name'].'<br>性別:'.$row['gender'].'<br>分數:'.$row['score'];
}
?>
⑶ php網頁怎麼找後台的資料庫在哪
通常php網站是使用php+mysql架構的。
這樣在網站中是無法直接找到資料庫的。只能找到鏈接資料庫的配置信息。主機、埠、資料庫名、用戶名、密碼等。
然後可以根據找到的信息,可以使用第三方的工具進行連接
⑷ php如何讀取資料庫
<?php
//建立資料庫鏈接,
mysql_connect("localhost","mysql_user","mysql_password")or
die("Couldnotconnect:".mysql_error());
//選擇資料庫
mysql_select_db("mydb");
//查詢sql語句
$result=mysql_query("SELECTid,nameFROMmytable");
//輸出查詢結果
while($row=mysql_fetch_array($result)){
echo$row['id'],"<br/>",$row['name'];
}
//釋放結果內存
mysql_free_result($result);
?>
⑸ php網站的資料庫怎麼查看
你可以使用phpmyadmin來進行查看,但是不太不明白你是要連接資料庫還是查看,有疑問可以找我。
⑹ php查詢資料庫
mysqli有兩種資料庫連接方式:
1、面向過程式連接:
mysqli_connect('localhost','xxx','xxx','xxx');
mysqli_query('');
後使用mysqli_fetch_assoc方法獲取到數據。
2、面向對象式連接:
$mysqli=newmysqli("localhost","my_user","my_password","world");
$result=$mysqli->query('');
後使用$result->fetch_assoc()獲取數據。
至於num_rows是獲取查詢到的行數的方法。
⑺ php如何獲取資料庫信息
代碼如下:?View
Code
PHP
include("conn.php");//調用資料庫連接文件
echo
"<table
width=572
height=56
border=0
cellspacing=1>
";
//創建html表格
echo
"<tr
bgcolor=#9999FF>";
echo
"<th
width=33
scope=col>id</th>";
echo
"<th
width=100
scope=col>user_name</th>
";
echo
"<th
width=100
scope=col>user_pass</th>
";
echo
"<th
width=100
scope=col>staus</th>";
echo
"<th
width=100
scope=col>insert_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原生語句查詢資料庫
原生SQL查詢有 query() 和 execute() 兩個方法:
query():用於 SQL 查詢操作,並返回符合查詢條件的數據集
execute():更新和寫入數據的 SQL 操作,返回影響的記錄數
query()
query() 方法是用於 SQL 查詢操作,和select()方法一樣返回符合查詢條件的數據集。
例子:
public function read(){
// 實例化一個空模型,沒有對應任何數據表
$Dao = M();
//或者使用 $Dao = new Model();
$list = $Dao->query("select * from user where uid<5");
if($list){
$this->assign('list', $list );
$this->display();
} else {
$this->error($Dao->getError());
}
}
對於 query() 方法返回的數據集,跟 select() 一樣,可以在模板里直接循環輸出。
execute()
execute() 方法用於更新和寫入數據的 SQL 操作(註:非查詢操作,無返回數據集),返回影響的記錄數。
例子:
public function read(){
header("Content-Type:text/html; charset=utf-8");
// 實例化一個空模型,沒有對應任何數據表
$Dao = M();
//或者使用 $Dao = new Model();
$num = $Dao->execute("update user set email = '[email protected]' where uid=3");
if($num){
echo '更新 ',$num,' 條記錄。';
}else{
echo '無記錄更新';
}
}
如果查詢比較復雜或一些特殊的數據操作不能通過 ThinkPHP 內置的 ORM 和 ActiveRecord 模式實現時,就可以通過直接使用原生 SQL 查詢來實現。
注意:以上都是 user 沒有表前綴的例子,在查詢語句中,查詢的表應該寫實際的表名字(包括前綴)。
⑼ php中選擇打開資料庫的方法是
在mysql資料庫中,創建一個test資料庫,用於測試。
總結:
1、創建一個test資料庫。
2、使用mysql_connect()函數創建一個資料庫的連接。
3、再使用mysql_select_db()函數選擇要操作的資料庫test,並通過if語句判斷結果。
⑽ php+mysql如何讀取資料庫數據
先配置資料庫------連接資料庫--------選擇資料庫--------填寫檢索表-------輸出檢索內容