php數(shù)據(jù)修改教程外包 php怎么實現(xiàn)修改數(shù)據(jù)功能

php數(shù)據(jù)庫添加、刪除、修改數(shù)據(jù)(mysql)

一、PHP操作MySql數(shù)據(jù)庫

創(chuàng)新互聯(lián)建站專注于汶上企業(yè)網(wǎng)站建設,響應式網(wǎng)站建設,商城網(wǎng)站定制開發(fā)。汶上網(wǎng)站建設公司,為汶上等地區(qū)提供建站服務。全流程按需網(wǎng)站開發(fā),專業(yè)設計,全程項目跟蹤,創(chuàng)新互聯(lián)建站專業(yè)和態(tài)度為您提供的服務

新增數(shù)據(jù)

?php

$query

=

"INSERT

INTO

grade

(name,email,point,regdate)

VALUE

('

李三','yc60.com@gmail.com',,NOW())"

;

@mysql_query($query)

or

die(

'添加數(shù)據(jù)出錯:'

.mysql_error());

?

修改數(shù)據(jù)

?php

$query

=

"UPDATE

grade

SET

name='小可愛'

WHERE

id=6"

;

@mysql_query($query)

or

die(

'修改出錯:'

.mysql_error());

?

刪除數(shù)據(jù)

?php

$query

=

"DELETE

FROM

grade

WHERE

id=6";

@mysql_query($query)

or

die(

'刪除錯誤:'

.mysql_error());

?

顯示數(shù)據(jù)

?php

$query

=

"SELECT

id,name,email,point

FROM

grade";

$result

=

@mysql_query($query)

or

die(

'查詢語句出錯:'

.mysql_error());

while

(!!

$row

=

mysql_fetch_array($result))

{

echo

$row[

'id'

].

'----'

.$row['name'

].'----'

.$row

['email'

].

'----'

.$row['point'

];

echo

'br

/

';

}

?

二、其他常用函數(shù)

mysql_f

etch_row()

:從結果集中取得一行作為枚舉數(shù)組

mysql_f

etch_assoc()

從結果集中取得一行作為關聯(lián)數(shù)組

mysql_f

etch_array()

從結果集中取得一行作為關聯(lián)數(shù)組,或數(shù)字數(shù)組,或二者兼有

mysql_f

etch_lengths

()

取得結果集中每個輸出的長度

mysql_f

ield_name():

取得結果中指定字段的字段名

mysql_num_rows():

取得結果集中行的數(shù)目

mysql_num_f

ields():取得結果集中字段的數(shù)目

mysql_get_client_inf

o()

取得

MySQL

客戶端信息

mysql_get_host_info():

取得

MySQL

主機信息

mysql_get_proto_info():

取得

MySQL

協(xié)議信息

mysql_get_server_inf

o()

取得

MySQL

服務器信息

如何用php修改數(shù)據(jù)庫中的數(shù)據(jù)

舉例如下:

創(chuàng)建userinfo_update.php頁面用于查詢用戶信息,先顯示信息,在修改:

先通過GET獲取用戶編號查詢用戶信息:

$sql = "select * from user_info where user_id='".$_GET['userId']."'";

$result = mysql_query($sql,$con);

if($row = mysql_fetch_array($result)){

}

頁面效果:

創(chuàng)建update.php文件,用于修改用戶信息:

使用到了mysql_affected_rows() 函數(shù)返回前一次 MySQL 操作所影響的記錄行數(shù)。

//通過post獲取頁面提交數(shù)據(jù)信息

$userId = $_POST[userId];

$userName = $_POST[userName];

$userAge = $_POST[userAge];

$sql = "update user_info set user_name='".$userName."',user_age=".$userAge." where user_id='".$userId."'";

mysql_query($sql,$conn);//執(zhí)行SQL

$mark? = mysql_affected_rows();//返回影響行數(shù)

$url = "userinf_select.php";

運行結果

創(chuàng)建delete.php文件,完成刪除用戶信息功能:

$userId = $_GET['userId'];

include 'connection.php';

$sql = "delete from user_info where user_id='".$userId."'";

mysql_query($sql,$con);

$mark? = mysql_affected_rows();//返回影響行數(shù)

if($mark0){

echo "刪除成功";

}else{

echo? "刪除失敗";

}

mysql_close($con);

運行結果:

怎么用php代碼來修改php的文件?

PHP 中的 file_get_contents() 與 file_put_contents() 函數(shù)可以實現(xiàn)

file_get_contents() 函數(shù)把整個文件讀入一個字符串中。

file_get_contents() 函數(shù)是用于將文件的內(nèi)容讀入到一個字符串中的首選方法。

file_get_contents(path,include_path,context,start,max_length)

參數(shù)說明

path 必需。規(guī)定要讀取的文件。

include_path 可選。如果也想在 include_path 中搜尋文件的話,可以將該參數(shù)設為 "1"。

context 可選。規(guī)定文件句柄的環(huán)境。

context 是一套可以修改流的行為的選項。若使用 null,則忽略。

start 可選。規(guī)定在文件中開始讀取的位置。該參數(shù)是 PHP 5.1 新加的。

max_length 可選。規(guī)定讀取的字節(jié)數(shù)。該參數(shù)是 PHP 5.1 新加的。

對 context 參數(shù)的支持是 PHP 5.0.0 添加的。

注釋:本函數(shù)可安全用于二進制對象。

file_put_contents() 函數(shù)把一個字符串寫入文件中。

file_put_contents(file,data,mode,context)

參數(shù)說明

file 必需。規(guī)定要寫入數(shù)據(jù)的文件。如果文件不存在,則創(chuàng)建一個新文件。

data 可選。規(guī)定要寫入文件的數(shù)據(jù)??梢允亲址?shù)組或數(shù)據(jù)流。

注釋:本函數(shù)可安全用于二進制對象。

例如:

需要修改的php文件 index.php (前提條件此文件需要有寫入的權限)

?php

$str = 'abc123';

?

處理的文件 update.php

?php

$conents = file_get_contents("index.php");

$conents = str_replace('abc','efg',$conents);

file_put_contents("index.php",$conents);

?

修改后的index.php 文件

?php

$str = 'efg123';

?

網(wǎng)頁標題:php數(shù)據(jù)修改教程外包 php怎么實現(xiàn)修改數(shù)據(jù)功能
新聞來源:http://muchs.cn/article48/ddciihp.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供自適應網(wǎng)站、域名注冊網(wǎng)站營銷、做網(wǎng)站、商城網(wǎng)站、關鍵詞優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作