導航:首頁 > 文件管理 > 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連接資料庫配置文件相關的資料

熱點內容
cad怎麼樣復制到另一個文件里 瀏覽:49
微信朋友圈被屏蔽知乎 瀏覽:673
現代密碼學視頻 瀏覽:388
小米5splus微信運動 瀏覽:813
熱血戰斗小說去哪個網站 瀏覽:281
小孩學哪個編程語言好 瀏覽:279
網站參數篩選怎麼做 瀏覽:627
幼兒編程有什麼問題 瀏覽:693
工商銀行app人工服務在哪裡 瀏覽:19
怎麼讓文件中全體內容往下移 瀏覽:783
魔獸爭霸126版本轉換器 瀏覽:984
word2003精簡版下載 瀏覽:703
微博跳轉appstore 瀏覽:537
打開文件時許可權a代表什麼 瀏覽:155
昆侖通態導出數據文件名 瀏覽:338
手機遷移數據為什麼需要重新登錄 瀏覽:958
錄入資料庫的圖片如何更改 瀏覽:132
怎樣獲取郵箱帳號和密碼 瀏覽:809
怎麼通過js實現回到指定頁面 瀏覽:140
如何用網路簽字 瀏覽:552

友情鏈接