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

熱點內容
淘寶javascript 瀏覽:62
3d列印機g代碼 瀏覽:887
神州行自助升級4g 瀏覽:41
如何在設置查看app中描述文件 瀏覽:85
string取子串java 瀏覽:884
音樂網站怎麼找 瀏覽:998
Note3wifidhcp配置文件 瀏覽:787
風險分析的程序包括 瀏覽:514
背書是什麼意思網路 瀏覽:524
初中生作文安卓版 瀏覽:36
文件名有哪些部分構成 瀏覽:429
天天手環微信 瀏覽:166
垃圾清理系統文件 瀏覽:341
找尋電腦的文件不知道放哪個路徑 瀏覽:472
java圖片縮小圖片 瀏覽:566
不做編程道通和元征哪個好 瀏覽:353
管線資料庫更新方法有哪些 瀏覽:191
js全選和反選 瀏覽:874
機械設計和編程哪個難學 瀏覽:739
二不管轉換成什麼格式文件都會 瀏覽:889

友情鏈接