當前位置:首頁 » 編程語言 » php增刪改查

php增刪改查

發布時間: 2022-01-11 23:01:59

『壹』 php封裝一個類能實現mysql資料庫的增刪改查

樓主整理代碼會好一點

『貳』 php封裝一個class類,實現mysql資料庫的增刪改查怎麼操做

class
sqlHelper{
public
$conn;
public
$dbname="資料庫名稱";
public
$username="資料庫用戶名";
public
$password="資料庫密碼";
public
$host="localhost";
//連接資料庫
public
function
__construct(){
$this->conn=mysql_connect($this->host,$this->username,$this->password);
if(!$this->conn){
die("連接失敗".mysql_error());
}
mysql_select_db($this->dbname,$this->conn);
}
//執行查詢語句
public
function
execute_dql($sql){
$res=mysql_query($sql,$this->conn);
return
$res;
}
//執行增填改語句
public
function
execute_dml($sql){
$b=mysql_query($sql,$this->conn);
if(!$b){
return
3;
}else{
if(mysql_affected_rows($this->conn)){
return
1;//表示OK
}else{
return
2;//表示沒有行收到影響
}
}
}
}

『叄』 如何用PHP代碼實現MySQL資料庫的增刪改查

<?php
$con = mysql_connect("localhost:3306","root","");

if (!$con) {
die('Could not connect: ' . mysql_error());
}

mysql_select_db("test", $con);

$result = mysql_query("SELECT * FROM user");

echo "<table border='1'>
<tr>
<th>Username</th>
<th>Password</th>
</tr>";

while($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['username'] . "</td>";
echo "<td>" . $row['password'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysql_close($con);

?>

從伺服器中獲取用戶所有信息(SQL SELECT語句)並以表格形式出現
<?php
$con = mysql_connect("localhost","root","");
if (!$con) {
die('Could not connect: ' . mysql_error());
}

mysql_select_db("test", $con);

mysql_query("DELETE FROM user WHERE username = '$_POST[username]'");

mysql_close($con);
?>

刪除該用戶所有信息delete.php
<?php
$con = mysql_connect("localhost:3306","root","");

if (!$con) {
die('Could not connect: ' . mysql_error());
}

mysql_select_db("test", $con);

$sql = "INSERT INTO user (username,password)
VALUES
('$_POST[username]','$_POST[password]')";

if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}

echo "1 record added";

mysql_close($con);

?>

注冊一個新用戶insert.php
<?php

$con = mysql_connect("localhost","root","");
if (!$con) {
die('Could not connect: ' . mysql_error());
}

mysql_select_db("test", $con);

mysql_query("UPDATE user SET password = '$_POST[password]' WHERE username = '$_POST[username]'");

mysql_close($con);
?>

修改一個用戶密碼update.php
<html>
<head>
<title>FORM</title>
</head>
<body>
<br />
<h1>Insert:</h1>
<form action="insert.php" method="post">
username:<input type="name" name="username"/>
<br />
password:<input type="password" name="password"/>
<input type="submit" value="submit"/>
</form>
<br /><hr /><br />
<h1>Delete</h1>
<form action="delete.php" method="post">
username:<input type="name" name="username" />
<br />
Are you sure?<input type="submit" value="sure" />
</form>
<br /><hr /><br />
<h1>Update</h1>
<form action="update.php" method="post">
username:<input type="name" name="username"/>
<br />
You want to change your password into:<input type="password" name="password"/>
<input type="submit" value="submit"/>
</form>
<br /><hr /><br />
</body>
</html>

以上三個功能的提交源Operate.html

『肆』 需要一個php的前端ajax增刪改查介面

ajax使用很簡單,他屬於非同步傳輸。也就是你將以from以post或者get形式提交,換成ajax形式了。
取消from,使用ajax內的get或者post方法將當前頁的所需數據傳遞到另一個執行頁面。
jquery不錯的框架,搜索下ajax就明白了。

『伍』 php增刪改查的添加怎麼添加性別代碼

方法/步驟

鏈接資料庫方法:conn.php 。
代碼如下:
<?php
$link=mysql_connect('localhost','root','tianqing')or die('資料庫連接錯誤');
mysql_select_db('studyexam',$link)or die('資料庫訪問錯誤');
mysql_query("set names 'utf8'");
?>

增加 add.php
代碼如下:
<?php
include("conn.php");//引入鏈接資料庫
if(!empty($_POST['tj'])){
$title=$_POST['title'];
$con=$_POST['con'];
echo $sql="insert into news(id,title,dates,contents) value (null,'$title',now(),'$con')" ;
mysql_query($sql);
echo"插入成功";
}
?>
<form action="add.php" method="post">
標題: <input type="text" name="title"><br /><br />
內容: <textarea rows="6" cols="55" name="con"></textarea><hr>
<input type="submit" name="tj" value="提交">
</form>

刪除del.php
代碼如下:
<?php
include("conn.php");//引入鏈接資料庫<pre name="code" class="html"><?php
include("conn.php");//引入鏈接資料庫
if(!empty ($_GET['id'])){
$sql="select * from news where id='".$_GET['id']."'";
$query=mysql_query($sql);
$rs=mysql_fetch_array($query);
}
if(!empty($_POST['sub'])){
$title=$_POST['title'];
$con=$_POST['con'];
$hid=$_POST['hid'];
$sql="update news set title='$title',contents='$con' where id='$hid' limit 1 ";
mysql_query($sql);
echo "<script> alert('更新成功'); location.href='index.php'</script>";
echo"更新成功";
}
?>
<form action="edit.php" method="post">
<input type="hidden" name="hid" value="<?php echo $rs['id']?>"/>
標題: <input type="text" name="title" value="<?php echo $rs['title']?>"><br>
內容: <textarea rows="5" cols="50" name="con"><?php echo $rs['contents']?></textarea><br>
<input type="submit" name="sub" value="發表">
</form></pre><br>
<?php
if(!empty($_GET['del'])){ $d=$_GET['del']; $sql="delete from news where id ='$d'"; } $query=mysql_query($sql); echo "刪除成功"; ?><p></p>
<pre></pre>
<br>

改 edit.php頁面
代碼如下:
<?php
include("conn.php");//引入鏈接資料庫
if(!empty ($_GET['id'])){
$sql="select * from news where id='".$_GET['id']."'";
$query=mysql_query($sql);
$rs=mysql_fetch_array($query);
}
if(!empty($_POST['sub'])){
$title=$_POST['title'];
$con=$_POST['con'];
$hid=$_POST['hid'];
$sql="update news set title='$title',contents='$con' where id='$hid' limit 1 ";
mysql_query($sql);
echo "<script> alert('更新成功'); location.href='index.php'</script>";
echo"更新成功";
}
?>
<form action="edit.php" method="post">
<input type="hidden" name="hid" value="<?php echo $rs['id']?>"/>
標題: <input type="text" name="title" value="<?php echo $rs['title']?>"><br>
內容: <textarea rows="5" cols="50" name="con"><?php echo $rs['contents']?></textarea><br>
<input type="submit" name="sub" value="發表">
</form></pre><br>

查詢select.php頁面
代碼如下:
<?php
include("conn.php");
$sql="select * from entries";//entries這是資料庫名詞,大家自己改
if($result=mysql_query($sql)){
/*
$num=mysql_num_rows($result)
for($i=1;$i<=$num;$i++);
*/
while($array=mysql_fetch_assoc($result)){
//$biaoti=$array['title'];
$neirong=$array['entry'];
$id=$array['entry_id'];
echo "<p>{$array['title']}</p><p>$neirong</p><p><a href='edit.php?id=$id'>編輯</a>
<a href='delete.php?id=$id'>刪除</a></p><hr />";
}
}
?>

『陸』 PHP如何把前端用戶的增刪改查操做記錄寫進資料庫表

做個日誌記錄表 每次增刪改查後 更新表 如

//記錄
$sql = "insert into `h_log_point2` set ";
$sql .= "h_userName = '" . $rss['h_buyUserName'] . "', ";
$sql .= "h_price = '" . $num . "', ";
$sql .= "h_type = '交易完成', ";
$sql .= "h_about = '交易ID:" . $id . "', ";
$sql .= "h_addTime = '" . date('Y-m-d H:i:s') . "', ";
$sql .= "h_actIP = '" . getUserIP() . "' ";
$db->query($sql);

echo '修改成功';

『柒』 PHP怎麼對多維數據進行增刪改查

你可以嵌套遍歷 在第二層遍歷的時候做一下數組的建名 當等於你的目標數組建名再做下一層的遍歷 為了代碼的高效 你也可以對該建名的數組判斷是否為空 如果為空就跳到下一次循環

『捌』 php中一個html頁面實現增刪改查

增加:insert into 表名(欄位1,欄位2,...) values('值1','值2',....) where 條件;
刪除:delete 表名
修改:update 表名 set 欄位名='值' where 條件;
查詢:select 欄位名 from 表名 where 條件;

『玖』 PHP如何實現增刪改查,具體應該看什麼課程

連接數據啊,通過php語句來操作資料庫,從而實現增刪查改
主要要看mysql的課程,以及php入門的課程,之後主攻php操作資料庫這一塊

『拾』 一個php文件怎麼寫上增刪改查 功能

PHP個人博客開發,發郵件回復原程序2252065614

熱點內容
好醫生連鎖店密碼多少 發布:2024-09-20 05:09:38 瀏覽:15
魔獸腳本代理 發布:2024-09-20 05:09:35 瀏覽:98
python登陸網頁 發布:2024-09-20 05:08:39 瀏覽:757
安卓qq飛車如何轉蘋果 發布:2024-09-20 04:54:30 瀏覽:178
存儲過程中in什麼意思 發布:2024-09-20 04:24:20 瀏覽:315
php顯示數據 發布:2024-09-20 03:48:38 瀏覽:501
源碼安裝軟體 發布:2024-09-20 03:44:31 瀏覽:354
入門編程游戲的書 發布:2024-09-20 03:31:26 瀏覽:236
e盒的演算法 發布:2024-09-20 03:30:52 瀏覽:144
win10登錄密碼如何修改登錄密碼 發布:2024-09-20 03:09:43 瀏覽:71