//連接數(shù)據(jù)庫(kù)
鐵山網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián),鐵山網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為鐵山近千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站制作要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的鐵山做網(wǎng)站的公司定做!
if(!$con = mysql_connect("localhost","root","root")){die(mysql_error());}
mysql_select_db("ali_xt");
mysql_query('set names utf8');
//找出ali_admin表的字段
$res = mysql_query('show columns from ali_admin');
//將數(shù)據(jù)給弄出來
$data = array();
while ($row = mysql_fetch_assoc($res, MYSQL_NUM)) {
$data[] = $row;
}
//隨機(jī)個(gè)數(shù),默認(rèn)5
$rand_times = 5;
$rand_times = count($data)$rand_times?count($data):$rand_times;
$result = array();
for( $i=0;$i$rand_times;$i++ ){
$result[] = $data[rand(0,count($data)-1)][0];
}
echo "pre";
print_r($result); //輸出5個(gè)隨機(jī)字段
mysql_close($con);
//純手寫的,不明白可以問我,記得給分
Oracle(甲骨文)是世界上最為流行的關(guān)系數(shù)據(jù)庫(kù)。它是大公司推崇的工業(yè)化的強(qiáng)有力的引擎。我們先看看其相關(guān)的函數(shù):
(1)integer
ora_logon(string
user
,
string
password)
開始對(duì)一個(gè)Oracle數(shù)據(jù)庫(kù)服務(wù)器的連接。
(2)integer
ora_open(integer
connection)
打開給出的連接的游標(biāo)。
(3)integer
ora_do(integer
connection,
string
query)
在給出的連接上執(zhí)行查詢。PHP生成一個(gè)指示器,解析查詢,并執(zhí)行之。
(4)integer
ora_parse(integer
cursor,
string
query)
解析一個(gè)查詢并準(zhǔn)備好執(zhí)行。
(5)boolean
ora_exec(integer
cursor)
執(zhí)行一個(gè)先前由ora_parse函數(shù)解析過的查詢。
(6)boolean
ora_fetch(integer
cursor)
此函數(shù)會(huì)使得一個(gè)執(zhí)行過的查詢中的行被取到指示器中。這使得您可以調(diào)用ora_getcolumn函數(shù)。
(7)string
ora_getcolumn(integer
cursor,
integer
column)
返回當(dāng)前的值。列由零開始的數(shù)字索引。
(8)boolean
ora_logoff(integer
connection)
斷開對(duì)數(shù)據(jù)庫(kù)服務(wù)器的鏈接。
以下是向ORACLE數(shù)據(jù)庫(kù)插入數(shù)據(jù)的示例程序:
html
headtitle向ORACLE數(shù)據(jù)庫(kù)中插入數(shù)據(jù)/title/head
body
form
action="?echo
$PHP_SELF;?"
method="post"
table
border="1"
cellspacing="0"
cellpadding="0"
tr
thID/th
thname/th
thDescription/th
/tr
tr
tdinput
type="text"
name="name"
maxlength="50"
size="10"/td
tdinput
type="text"
name="email"
maxlength="255"
size="30"/td
tdinput
type="text"
name="Description"
maxlength="255"
size="50"/td
/tr
tr
align="center"
td
colspan="3"input
type="submit"
value="提交" input
type="reset"
value="重寫"/td
/tr
/table
/form
?
//先設(shè)置兩個(gè)環(huán)境變量ORACLE_HOME,ORACLE_SID
putenv("ORACLE_HOME=/oracle/app/oracle/product/8.0.4");
putenv("ORACLE_SID=ora8");
//設(shè)置網(wǎng)頁(yè)顯示中文
putenv("NLS_LANG=Simplified_Chinese.zhs16cgb231280");
if($connection=ora_logon("scott","tiger"))
{
//庫(kù)表test有ID,name,Description三項(xiàng)
$sql
=
'insert
into
test(ID,name,Description)
values
';
$sql
.=
'(''
.
$ID
.
'',''
.
$name
.
'',''.
$Description
.
'')';
if($cursor=ora_do($connect,$sql))
{
print("insert
finished!");
}
$query
=
'select
*
from
test';
if($cursor=ora_do($connect,$query))
{
ora_fetch($cursor);
$content0=ora_getcolumn($cursor,0);
$content1=ora_getcolumn($cursor,1);
$content2=ora_getcolumn($cursor,2);
print("$content0");
print("$content1");
print("$content2");
ora_close($cursor);
}
ora_logoff($connection);
}
?
/body
/html
不用從頁(yè)面取id
去掉foreach
$sql="select * from phome_ecms_wma order by rand() limit 30"
就行了
select * from tableName where id 0 AND id 60 order by rand()
如果id有刪除,用這個(gè):
select * from (select * from tableName order by id ASC limit 0, 60 ) as tmp order by rand();
rand()是 mysql 自己的函數(shù),取出數(shù)據(jù)后,按隨機(jī)排序
網(wǎng)站標(biāo)題:php隨即調(diào)用數(shù)據(jù)庫(kù) php 數(shù)據(jù)庫(kù)操作
鏈接地址:http://chinadenli.net/article4/dodscie.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)建站、ChatGPT、軟件開發(fā)、云服務(wù)器、建站公司、動(dòng)態(tài)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)