導航:首頁 > 源碼編譯 > 增刪改查php源碼

增刪改查php源碼

發布時間:2022-12-21 07:18:20

Ⅰ 如何在phpCMS的後台代碼中實現增刪改查

$this->db->update(array('is_login'=>0),array('username'=>$username));

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

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

Ⅲ 求php增刪改查代碼。

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連接Access資料庫並實現簡單增刪查改語句的代碼塊

給你兩個我自己寫的資料庫的操作的class吧
這個是為了 同時可以使用access和mysql而做的 先弄一個mysql的 然後又寫一個access的 所有的函數一一對應 你可以看下 絕對原創喔~~
配置文件如下
$config['db']['type'] = "Mysql"; //資料庫類型「Mysql」,「Access」
$config['db']['database']= "ourcms"; //資料庫(文件)名
$config['db']['host'] = ""; //資料庫主機
$config['db']['username']= "7king"; //資料庫連接用戶名
$config['db']['password']= "tingting"; //資料庫連接密碼

/*
$config['db']['type'] = "Access"; //資料庫類型「Mysql」,「Access」
$config['db']['database']= "ourcms.mdb";//資料庫(文件)名
$config['db']['host'] = "";
$config['db']['username']= "";
$config['db']['password']= "";

<?php
/**
* 2007.04 by zhaohe
*
* php連接access通用類
*
* 用法:
* 建立new Access類 => set_db設置數據路徑 => set_login 設置連接資料庫的用戶名和密碼
* => 通過set_conn 設置連接 =>
* {
get_result 獲取查詢執行結果; get_result_rows 獲取查詢執行列表,一般是select
insert_info 插入新的記錄 update_info更新記錄
}
*
*
*/

class Access {
/**
* 類變數定義
* @param $conn mysql連接號
* @param $error 錯誤代號
* @param $username/$password 資料庫連接用戶名和密碼
* @param array $err_info 錯誤信息
*
* @param $debuginfo 調試信息
* @param $table 當前操作數據表
*/
var $conn;
var $error;
var $database;
var $username = "";
var $password = "";
var $err_info = array(
0 => "沒有錯誤!",
1 => "資料庫連接失敗!",
2 => "sql執行出錯!"
);
var $debuginfo="";
var $table;

/**
* 默認構造方法
**/
function Access( $arr=null ){
if( is_array($arr) ) {
$this->set_login( $arr['host'] , $arr['username'] , $arr['password'] );
$this->set_db( $arr['database'] );
$this->set_conn();
}
}

/**
* 設置資料庫文件名
* @param string $dbfile
*
* return void
*/
function set_db ( $dbfile ){
$this->database = $dbfile;
}

/**
* 設置連接資料庫的用戶名和密碼
* @param string $user 用戶名
* @param string $pwd 密碼
*
* @return void
*/
function set_login ( $user , $pwd ){

$this->username=$user;
$this->password=$pwd;

}

/**
* 創建資料庫連接
* @param
* return void
*/
function set_conn ( ){

if($this->conn=odbc_connect("DRIVER=Microsoft Access Driver (*.mdb);DBQ=".realpath($this->database),$this->username,$this->password,SQL_CUR_USE_ODBC )) $this->error=0;
else $this->error=1;
}

/**
* 設置當前操作的數據表
* @param string $tb
*
* @return void
*/
function set_table( $tb ) {
$this->table = $tb;
}

/**
* 返回sql查詢結果
* @param string $sql sql語句
*
* @return #id
*/
function get_result( $sql ){
return odbc_do( $this->conn , $sql );
}

/**
* 獲取查詢的結果
* @param string $sql
*
* @return array 結果的二維數組
*/
function get_result_rows( $sql ){

$array = array() ;
$result = $this->get_result( $sql );
while( $row = odbc_fetch_array( $result ) )
$array[] = $row ;
return $array;
}

/**
* 獲取部分查詢結果
*
* @param Array 數組
* @return Array
*/
function get_query_result( $cols , $tb=null , $order=null , $limit=null , $start=0 ) {
if( empty($tb) ) $tb=$this->table;
else $this->table=$tb;

if( is_array($cols) ) $col="[".implode('],[',$cols)."]";
else $col = $cols;

if( empty($limit) )
$sql = "select $col from $tb";
else
$sql ="select top $limit $col from $tb";;
if( isset($order) ) $sql.=" order by $order";

return $this->get_result_rows($sql);
}

/**
* 執行資料庫插入操作
*
* @param $arr values列表,數組索引為數據表欄位
* @param $tb 操作數據表 如果為空則為設置的當前類的操作表
*/
function insert_info( $arr , $tb = "" ) {

$cols = array_keys( $arr );
$values = array_values( $arr );

if (empty($tb)) $tb = $this->tb;
/*
foreach( $arr as $key => $value ){
$cols[] = $key;
$values[] = $value;
}
*/
$sql = "insert into [$tb]([".implode("],[",$cols)."]) values('".implode("','",$values)."')";
//return $sql;
return $this->get_result( $sql );
}

/**
* 執行資料庫更新操作
*
* @param array $arr 要更新的欄位值 數組索引為表欄位名
* @param array $con 條件數組
* @param string $tb 要操作的數據表
*
*/
function update_info( $arr , $con , $tb = "" ) {

$cols = array();
$conditions = array();

if (empty( $tb )) $tb = $this->tb;

foreach( $arr as $key => $value ){
$cols[] = "[$key]='$value'";
}

foreach( $con as $key => $value ) {
//檢查數據類型
if( is_int($value) || is_float($value) )
$conditions[] = "[$key]=$value";
else
$conditions[] = "[$key]='$value'";
}

$sql = "update [$tb] set ".implode(",",$cols)." where ".implode(" and ",$conditions);
//return $sql;
return $this->get_result( $sql );
}

}
?>

mysql的類如下
class Mysql {
/**
* mysql連接執行類,將sql的執行實現資料庫無關性
*
*
*
*/

/**
* 類變數定義
* @param $conn mysql連接號
* @param $error 錯誤代號
* @param $username/$password 資料庫連接用戶名和密碼
* @param array $err_info 錯誤信息
*
* @param $debuginfo 調試信息
* @param $table 當前操作數據表
*/
var $conn;
var $error;
var $username = "";
var $password = "";
var $host;
var $database;
var $err_info = array(
0 => "沒有錯誤!",
1 => "資料庫連接失敗!",
2 => "sql執行出錯!"
);
var $debuginfo="";
var $table;

function Mysql( $arr=null ) {
if( is_array($arr) ) {//var_mp($arr);
$this->set_login( $arr['host'] , $arr['username'] , $arr['password'] );
$this->set_db( $arr['database'] );
$this->set_conn();
if( isset($this->error) && $this->error!=0 ) die($this->err_info[$this->error]);
}
}

/**
* 設置資料庫名
* @param string $database
*
* return void
*/
function set_db ( $dbfile ){
$this->database = $dbfile;
}
/**
* 設置連接資料庫的用戶名和密碼
* @param string $user 用戶名
* @param string $pwd 密碼
*
* @return void
*/
function set_login ( $host , $user , $pwd ){

$this->host=$host;
$this->username=$user;
$this->password=$pwd;

}

/**
* 創建資料庫連接
* @param
* return void
*/
function set_conn (){

$this->conn=mysql_connect($this->host,$this->username,$this->password );

if ( isset($this->conn) && mysql_select_db($this->database) )
$this->error=0;
else
$this->error=1;
}

/**
* 設置當前操作的數據表
* @param string $tb
*
* @return void
*/
function set_table( $tb ) {
$this->table = $tb;
}

/**
* 返回sql查詢結果
* @param string $sql sql語句
*
* @return #id
*/
function get_result( $sql ){
return mysql_query( $sql , $this->conn );
}

/**
* 獲取查詢的結果
* @param string $sql
*
* @return array 結果的二維數組
*/
function get_result_rows( $sql ){
$array = array() ;
$result = $this->get_result( $sql );
while( $row = mysql_fetch_assoc( $result ) )
$array[] = $row ;
return $array;
}

/**
* 獲取部分查詢結果
*
* @param Array 數組
* @return Array
*/
function get_query_result( $cols , $tb=null , $condition , $order=null , $limit=null , $start=0 ) {
if( empty($tb) ) $tb=$this->table;
else $this->table=$tb;
if( is_array($cols) ) $col="`".implode('`,`',$cols)."`";
else $col = $cols;

if( isset($limit) )
$sql.="select top $limit $col from $tb";
else
$sql = "select $col from $tb";
if( isset($condition) ) $sql.=" where $condition";
if( isset($order) ) $sql.=" order by $order";
if( isset($limit) ) $sql.=" limit $start,$limit";

return $this->get_result_rows($sql);
}

/**
* 執行資料庫插入操作
*
* @param $arr values列表,數組索引為數據表欄位
* @param $tb 操作數據表 如果為空則為設置的當前類的操作表
*/
function insert_info( $arr , $tb = "" ) {

$cols = array_keys( $arr );
$values = array_values( $arr );

if (empty($tb)) $tb = $this->table;
/*
foreach( $arr as $key => $value ){
$cols[] = $key;
$values[] = $value;
}
*/
$sql = "insert into [$tb](`".implode("`,`",$cols)."`) values('".implode("','",$values)."')";
//return $sql;
return $this->get_result( $sql );
}

/**
* 執行資料庫更新操作
*
* @param array $arr 要更新的欄位值 數組索引為表欄位名
* @param array $con 條件數組
* @param string $tb 要操作的數據表
*
*/
function update_info( $arr , $con , $tb = "" ) {

$cols = array();
$conditions = array();

if (empty( $tb )) $tb = $this->table;

if( is_array($arr) ) {
foreach( $arr as $key => $value ){
$cols[] = "`$key`='$value'";
}

foreach( $con as $key => $value ) {
//檢查數據類型
if( is_int($value) || is_float($value) )
$conditions[] = "`$key`=$value";
else
$conditions[] = "`$key`='$value'";
}

$sql = "update `$tb` set ".implode(",",$cols)." where ".implode(" and ",$conditions);
}
else
$sql = "update `$tb` set $arr where $con";
//return $sql;
return $this->get_result( $sql );
}
}

Ⅳ 如何用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怎麼對多維數據進行增刪改查

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

Ⅶ 求一個php期末大作業的源碼(包括素材) ,可以實現增刪改查功能就可以

。。如果沒有其他要求,你只要:

①安裝環境,如集成xmapp

②自己隨便建個表,沒其他需求倆欄位就夠了。

③下個yii源碼包,用自帶gii工具生成一套crud。

over。

Ⅷ 一個php文件怎麼寫上增刪改查 功能

<?php
class dbClass()
{
function __construct()
{
//連接mysql

}

function add()
{

}
function del()
{

}
function update()
{

}
}

$db = new dbClass();
可以在請求參數里增加一個type,根據不同的type來調用不同的方法

?>

Ⅸ 簡單的php增刪改查,求助大俠們幫忙。急!

暈,Qeephp不是有快速入門的文檔嘛,下一個好好學習學習就知道了。

Ⅹ 如何修改PHP的源碼

PHP源碼用記事本就可打開編輯了,當然用DW也可以。圖片背景要改,可要看清圖片的鏈接(或者直接將圖片改成你要的圖片也可),改文字格式要通過CSS來修改,鏈接的話,應該在網站後台就能修改。
不過,這樣改太累了點!而且PHP的網頁無法直接在IE中預覽。
建議你下載一個DEDECMS的企業版,然後把相關的圖片(如Logo.gif)改成自己的,網站的頻道(欄目)、鏈接都可以在安裝後改。

閱讀全文

與增刪改查php源碼相關的資料

熱點內容
廣播PDF 瀏覽:216
單片機編程300例匯編百度 瀏覽:33
騰訊雲連接不上伺服器 瀏覽:221
不能用來表示演算法的是 瀏覽:859
6軸機器人演算法 瀏覽:890
手機主題照片在哪個文件夾 瀏覽:294
安卓手機後期用什麼軟體調色 瀏覽:628
cad修改快捷鍵的命令 瀏覽:242
好錢包app怎麼登錄不了 瀏覽:859
樹莓派都用python不用c 瀏覽:757
access文件夾樹的構造 瀏覽:662
安卓多指操作怎麼設置 瀏覽:658
linux樹形目錄 瀏覽:727
平方根的簡單演算法 瀏覽:898
千牛訂單頁面信息加密取消 瀏覽:558
單片機自製紅外遙控燈 瀏覽:719
伺服器最小配置怎麼弄 瀏覽:853
ibm伺服器硬體如何升級 瀏覽:923
全球程序員節點贊 瀏覽:986
php函數傳遞數組 瀏覽:632