需要PHP基礎知識和數(shù)據(jù)庫基礎知識。

專注于為中小企業(yè)提供成都做網(wǎng)站、成都網(wǎng)站建設、成都外貿網(wǎng)站建設服務,電腦端+手機端+微信端的三站合一,更高效的管理,為中小企業(yè)扶綏免費做網(wǎng)站提供優(yōu)質的服務。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了上千企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設實現(xiàn)規(guī)模擴充和轉變。
以SQL為例。使用PHP MySQL 函數(shù)可以編輯數(shù)據(jù)庫。
mysql_connect() 函數(shù)打開MySQL 連接。舉例
?php
$con = mysql_connect("localhost","mysql_user","mysql_pwd");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}// 一些代碼...mysql_close($con);
?
mysql_connect()三個參數(shù)分別是服務器名,連接賬號,連接密碼。
連接之后,可以使用mysql_select_db()設置要處理的數(shù)據(jù)庫,后面則是用數(shù)據(jù)庫語句處理數(shù)據(jù)。SQL語法簡介網(wǎng)頁鏈接
php鏈接mysql必備條件:
已安裝mysql數(shù)據(jù)庫;
檢查php環(huán)境是否已開啟mysql擴展(一般情況下是開啟的);
檢查方法:a.使用phpinfo();函數(shù),看有沒有mysql項;b.打開php.ini文件,檢查php_mysql.dll前分號是否已取掉。
php鏈接代碼如下:
?php
//設置編碼格式
header("Content-type:text/html;charset=utf-8");
//定義數(shù)據(jù)庫主機地址
$host="localhost";
//定義mysql數(shù)據(jù)庫登錄用戶名
$user="root";
//定義mysql數(shù)據(jù)庫登錄密碼
$pwd="";
//鏈接數(shù)據(jù)庫
$conn = mysql_connect($host,$user,$pwd);
//對連接進行判斷
if(!$conn){
die("數(shù)據(jù)庫連接失敗!".mysql_errno());
}else{
echo "數(shù)據(jù)庫連接成功!";
}
?
直接寫代碼啊。
我寫了一遍截圖看。第一行參數(shù)主機、用戶名、密碼;第二行選擇數(shù)據(jù)庫‘第三行選擇字符集’
你自己試下
//鏈接數(shù)據(jù)庫
$db=mysql_connect("localhost", "root","123456");
$sqlname="database";
mysql_select_db($sqlname,$db);
session_start();
mysql_query("SET NAMES 'utf8'",$db);
?
?
//創(chuàng)建結果集
$sql = "SELECT * FROM kecheng";
$result = mysql_query($sql);
$rs= mysql_fetch_array($result);
?
?
//修改數(shù)據(jù)
$sql = "UPDATE news SET title='1111' where news_id=1";
$result = mysql_query($sql);
?
?
//刪除數(shù)據(jù)
$sql = "DELETE from news where news_id=1";
$result = mysql_query($sql);
?
?
//添加數(shù)據(jù)
$sql = "INSERT INTO news (title,fenshu) VALUES ('a',1)"
$result = mysql_query($sql);
?
PHP鏈接數(shù)據(jù)庫有幾種方式
mysqli:
?php
$servername = "localhost";
$username = "username";
$password = "password";
// 創(chuàng)建連接
$conn = new mysqli($servername, $username, $password);
// 檢測連接
if ($conn-connect_error) {
die("連接失敗: " . $conn-connect_error);
}
echo "連接成功";
?
也可以使用PDO進行鏈接,前提是你必須在php.ini中開啟PDO:
?php
$servername = "localhost";
$username = "username";
$password = "password";
try {
$conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password);
echo "連接成功";
}
catch(PDOException $e)
{
echo $e-getMessage();
}
?
建議使用PDO,功能更加強大,兼容各種數(shù)據(jù)庫
關于這個問題,差不多就是這個樣子的了,你如果不明白,可以自己去后盾瞅瞅,我這些都是在后盾上學的,有空可以去看一下,就算不喜歡也沒關系啊,何樂而不為呢?
Oracle(甲骨文)是世界上最為流行的關系數(shù)據(jù)庫。它是大公司推崇的工業(yè)化的強有力的引擎。我們先看看其相關的函數(shù):
(1)integer
ora_logon(string
user
,
string
password)
開始對一個Oracle數(shù)據(jù)庫服務器的連接。
(2)integer
ora_open(integer
connection)
打開給出的連接的游標。
(3)integer
ora_do(integer
connection,
string
query)
在給出的連接上執(zhí)行查詢。PHP生成一個指示器,解析查詢,并執(zhí)行之。
(4)integer
ora_parse(integer
cursor,
string
query)
解析一個查詢并準備好執(zhí)行。
(5)boolean
ora_exec(integer
cursor)
執(zhí)行一個先前由ora_parse函數(shù)解析過的查詢。
(6)boolean
ora_fetch(integer
cursor)
此函數(shù)會使得一個執(zhí)行過的查詢中的行被取到指示器中。這使得您可以調用ora_getcolumn函數(shù)。
(7)string
ora_getcolumn(integer
cursor,
integer
column)
返回當前的值。列由零開始的數(shù)字索引。
(8)boolean
ora_logoff(integer
connection)
斷開對數(shù)據(jù)庫服務器的鏈接。
以下是向ORACLE數(shù)據(jù)庫插入數(shù)據(jù)的示例程序:
html
headtitle向ORACLE數(shù)據(jù)庫中插入數(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
?
//先設置兩個環(huán)境變量ORACLE_HOME,ORACLE_SID
putenv("ORACLE_HOME=/oracle/app/oracle/product/8.0.4");
putenv("ORACLE_SID=ora8");
//設置網(wǎng)頁顯示中文
putenv("NLS_LANG=Simplified_Chinese.zhs16cgb231280");
if($connection=ora_logon("scott","tiger"))
{
//庫表test有ID,name,Description三項
$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
網(wǎng)站標題:php數(shù)據(jù)庫如何使用方法 php數(shù)據(jù)庫如何使用方法查詢
URL網(wǎng)址:http://chinadenli.net/article26/hihsjg.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供外貿建站、定制開發(fā)、企業(yè)網(wǎng)站制作、營銷型網(wǎng)站建設、域名注冊、服務器托管
聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)