導航:首頁 > 文件管理 > mysqlphp連接資料庫配置文件

mysqlphp連接資料庫配置文件

發布時間:2025-03-13 11:33:07

1. php怎麼連接mysql資料庫

1、新建一個php_mysql.php的文件


2. php連接 mysql 資料庫如何添加一個公共的配置文件

php面向對象文件名DB.class.php

<?php
header("content-type:text/html;charset=utf-8");
classDB{
public$db_host;//localhost
public$db_user;//用戶名
public$db_pwd;//密碼
public$db_name;//資料庫名
public$links;//鏈接名稱
//構造方法的參數和屬性名字一致,但是含義不同
function__construct($db_host,$db_user,$db_pwd,$db_name){
$this->db_host=db_host;
$this->db_user=db_user;
$this->db_pwd=db_pwd;
$this->db_name=db_name;
//鏈接資料庫代碼
$this->links=@mysql_connect($db_host,$db_user,$db_pwd)ordie("資料庫鏈接失敗");
//echo$this->links;列印是資源
mysql_query("setnamesutf8");
mysql_select_db($db_name,$this->links);

}
functionquery($sql){//執行各種sql,inertupdatedelete執行,如果執行select返回結果集
returnmysql_query($sql);
}
functionnumRows($sql){//返回select的記錄數
$result=$this->query($sql);
$count=mysql_num_rows($result);
return$count;
}
functiongetOne($sql){//得到一條記錄的一維數組
$result=$this->query($sql);
$arr=mysql_fetch_assoc($result);
return$arr;
}
functiongetAll($sql){//得到多條記錄的二維數組
$result=$this->query($sql);
$rows=array();
while($rs=mysql_fetch_assoc($result)){
$rows[]=$rs;
}
return$rows;
}
function__destruct(){
$this->db_host=db_host;
$this->db_user=db_user;
$this->db_pwd=db_pwd;
$this->db_name=db_name;
}
}

$db=newDB("localhost","root","","car");
//$sql="insertintocategory(categoryName)values('常熟seo')";
//$db->query($sql);

//返回select的記錄數
//$sql="select*fromcategory";
//$count=$db->numRows($sql);
//echo$count;

//得到一條記錄的一維數組
//$sql="select*fromcategorywherecategoryId=1";
//$arr=$db->getOne($sql);
//print_r($arr);

//得到多條記錄的二維數組
$sql="select*fromcategory";
$rs=$db->getAll($sql);
print_r($rs);


?>

創建一個資料庫大類

閱讀全文

與mysqlphp連接資料庫配置文件相關的資料

熱點內容
怎麼用鍵盤拷貝u盤文件 瀏覽:664
js炫酷特效 瀏覽:69
什麼樣的app最有市場 瀏覽:563
騰訊地圖如何截圖工具 瀏覽:69
數據處理主要方法有哪些 瀏覽:567
ps6拖文件無法打開 瀏覽:668
有哪些比較好的書評app 瀏覽:520
java中char表示範圍 瀏覽:154
python編程操作題如何批改 瀏覽:1
網路是什麼原理圖 瀏覽:670
apk音樂提取工具 瀏覽:89
怎樣共享wifi密碼設置 瀏覽:281
javamesdk8 瀏覽:503
屬於聲音格式的文件有哪些 瀏覽:373
漢字書法的app有哪些 瀏覽:801
迅捷fwr310v1升級 瀏覽:782
三星有密碼鎖可以關機 瀏覽:293
游戲編程設計怎麼做 瀏覽:509
臉譜網賬號密碼大全 瀏覽:98
編程貓什麼時候才能登錄 瀏覽:600

友情鏈接