當前位置:首頁 » 數據倉庫 » php抓取表格資料庫
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

php抓取表格資料庫

發布時間: 2023-02-06 00:57:35

1. php讀取資料庫信息的幾種方法

連接到一個url地址為localhost、埠為3306的mysql伺服器上。mysql伺服器的帳號是"root",密碼是"9999"。mysql伺服器上有一個資料庫ok,資料庫里有一個表abc。表abc一共為兩列,列名分別是"id"和"name",將abc里的所有數據讀出來。

<?
$dbh=@mysql_connect("localhost:3306","root","9999");
/*定義變數dbh,mysql_connect()函數的意思是連接mysql資料庫,"@"的意思是屏蔽報錯*/
if(!$dbh){die("error");}
/*die()函數的意思是將括弧里的字串送到瀏覽器並中斷PHP程式(Script)。括弧里的參數為欲送出的字串。*/
@mysql_select_db("ok",$dbh);
/*選擇mysql伺服器里的一個資料庫,這里選的資料庫名為ok*/
$q="SELECT*FROMabc";
/*定義變數q,"SELECT*FROMabc"是一個SQL語句,意思是讀取表abc中的數據*/
?>
<br/>
<!--=========方法一=========-->
<br/>
<?
$rs=mysql_query($q,$dbh);
/*定義變數rs,函數mysql_query()的意思是:送出query字串供MySQL做相關的處理或者執行.由於php是從右往左執行的,所以,rs的值是伺服器運行mysql_query()函數後返回的值*/
if(!$rs){die("Validresult!");}
echo"<table>";
echo"<tr><td>ID</td><td>Name</td></tr>";
while($row=mysql_fetch_row($rs))echo"<tr><td>$row[0]</td><td>$row[1]</td></tr>";
/*定義量變(數組)row,並利用while循環,把數據一一寫出來.
函數mysql_fetch_row()的意思是:將查詢結果$rs單列拆到陣列變數中.
$row[0]和$row[1]的位置可以換*/
echo"</table>";
?>
<br/>
<!--=========方法二=========-->
<br/>
<?
$rs=mysql_query($q,$dbh);
while($row=mysql_fetch_object($rs))echo"$row->id$row->name<br/>";
/*id和name可以換位置*/
?>
<br/>
<!--=========方法三=========-->
<br/>
<?
$rs=mysql_query($q,$dbh);
while($row=mysql_fetch_array($rs))echo"$row[id]$row[name]<br/>";
/*id和name可以換位置*/
?>
<!--=========方法三最快=========-->
<?
@mysql_close($dbh);
/*關閉到mysql資料庫的連接*/
?>

2. 如何php語言將excel表中的數據提取到mysql資料庫中

思路:讀取excel每行,分別獲取各個值賦予各個變數,之後組裝sql插入mysql
php讀取excel,網上有很多插件、封裝好的類,你可以下載一個

3. php如何取資料庫中內容

試編寫代碼如下:

<?php
//從資料庫根據id獲取顏色
functiongetColor($db,$id)
{
if($result=$db->query("SELECT*FROMcolorwhereid='".$id."'"))
{
$row=$result->fetch_assoc();
return$row['color'];
}
return'#000000';
}

$mysqli=newmysqli("localhost","test","test","room");

if($mysqli->connect_error){
printf("資料庫連接錯誤:%s ",mysqli_connect_error());
exit();
}

?>
<tableborder="1"cellspacing="0">
<tr>
<tdbgcolor="<?phpechogetColor($mysqli,'1')?>">1</td>
</tr>
<tr>
<tdbgcolor="<?phpechogetColor($mysqli,'2')?>">2</td>
</tr>
<tr>
<tdbgcolor="<?phpechogetColor($mysqli,'3')?>">3</td>
</tr>
</table>

<?php

$mysqli->close();

?>

4. 如何用php取出資料庫表中一列所有數據

用該列的欄位名即可,select語句的通用形式如下:
select 你要的信息
from 數據表(一個或多個)
where 滿足的條件
所以你的sql語句為:
select 要取得列名 from 表名 where 1
例子
SELECT id FROM `article` where 1

5. 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>";輸出記錄截圖

6. PHP如何獲取資料庫表中個欄位的數據

<?php
$servername="localhost";
$username="root";
$password="password";//mysql密碼
$dbname="myDB";//選擇資料庫

//創建連接
$conn=newmysqli($servername,$username,$password,$dbname);
//檢測連接
if($conn->connect_error){
die("Connectionfailed:".$conn->connect_error);
}

$sql="SELECTid,firstname,lastnameFROMMyGuests";//sql查詢語句
$result=$conn->query($sql);//獲得查詢結果

if($result->num_rows>0){
//輸出每行數據
while($row=$result->fetch_assoc()){
echo"<br>id:".$row["id"]."-Name:".$row["firstname"]."".$row["lastname"];
}
}else{
echo"0results";
}
$conn->close();
?>

7. PHP讀取資料庫

PHP的數據處理有點麻煩,建議你去了解一下這方面的知識,然後在來做,後盾網就有一些教學視頻和資料

8. 怎樣藉助PHP從HTML網頁中獲取phpmyadmin資料庫里數據表的內容

<?php
$link=mysql_connect('localhost','用戶名','密碼')ordie("資料庫連接失敗");//連接資料庫
mysql_select_db('資料庫名',$link);//選擇資料庫
mysql_query("setnamesutf8");//設置編碼格式
$q="select*from"數據表";//設置查詢指令
$result=mysql_query($q);//執行查詢
while($row=mysql_fetch_assoc($result))//將result結果集中查詢結果取出一條
{echo返回到HTML;}
?>

html界面使用ajax的成功返回值,再渲染在界面里就行了

9. php怎麼讀取excel並存入資料庫 簡書

用 php Win32 OLE

##Using OLE;

read('Book1.xls');

// print number of rows, columns and sheets
echo "Number of sheets: " . sizeof($excel->sheets) . "\n";
for ($x=0; $xsheets); $x++) {
echo "Number of rows in sheet " . ($x+1) . ": " . $excel->sheets[$x]["numRows"] . "\n";
echo "Number of columns in sheet " . ($x+1) . ": " . $excel->sheets[$x]["numCols"] . "\n";明白了吧,不會可以找我,我去忙活我的去後盾人學習了,加油@(/o・ェ・o)@/