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

熱點內容
大數據採集需要注意什麼 瀏覽:64
數控車外圓怎麼編程視頻 瀏覽:446
excel表格插入源文件 瀏覽:837
紅河州網站推廣多少錢 瀏覽:122
深度學習為什麼要對數據多次訓練 瀏覽:940
js刷新頁面後執行方法 瀏覽:391
網路731代表什麼意思 瀏覽:25
程序員馬化騰 瀏覽:118
iphone為什麼主屏幕app自動復位 瀏覽:433
word動作 瀏覽:18
清除文件管理的數據會怎麼樣 瀏覽:617
口袋德州39版本安卓 瀏覽:795
用藍牙接收文件在哪裡 瀏覽:762
c語言文件加密例題 瀏覽:378
kingstonu盤修復工具 瀏覽:683
別人百度網盤分享的文件在哪裡看 瀏覽:791
三國全面戰爭音效文件 瀏覽:571
提車都帶走哪些文件 瀏覽:330
情感類網站有哪些 瀏覽:173
蘇州有哪些大學開設編程 瀏覽:298

友情鏈接