構(gòu)造函數(shù)錯(cuò)咯
創(chuàng)新互聯(lián)建站于2013年創(chuàng)立,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目網(wǎng)站建設(shè)、成都做網(wǎng)站網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元?dú)J州做網(wǎng)站,已為上家服務(wù),為欽州各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:13518219792
function?__construct($host,$user,$pass,$database){
$this?-?host=$host;
$this?-?user=$user;
$this?-?pass=$pass;
$this?-?database=$database;
//?echo?$db;
$conn?=?mysql_connect($host,$user,$pass);
$db?=?mysql_select_db($this?-?database,$conn);
if($db){
echo?"數(shù)據(jù)庫成功";
}else{
echo?"數(shù)據(jù)庫失敗";
}
}
//給你改咯哈這個(gè)類
class?register{
private?$host;????????//The?host?address
private?$user;????????//The?user
private?$pass;????//The?password
private?$database;??????????//The?database
private?$conn;
//Connect?with?the?database
function?__construct($host,$user,$pass,$database){
$this?-?host=$host;
$this?-?user=$user;
$this?-?pass=$pass;
$this?-?database=$database;??????????
$conn?=?mysql_connect($host,$user,$pass)or?die("連接失敗!");
mysql_select_db($this?-?database,$conn)?or?die("選擇數(shù)據(jù)庫失敗!");
$this-conn=$conn;
}
//Add?a?user
function?addUser($data){
$dataObj????=?????$data;//類里邊不要把變量寫得太死
$userInfo???=?????json_decode($dataObj,true);??//change?the?data?from?the?type?of?json?to?array.
$username???=?????$userInfo[0];
$password???=?????$userInfo[1];
$repassword?=?????$userInfo[2];
//The?sql?to?add?the?new?user
@$sql_addUser?=?EOF
insert?into?users?values("","$username","$password","$repassword");
EOF;
//?var_dump($sql_addUser);break;
$result?=?mysql_query($sql_addUser,$this-conn);//指定連接,少些麻煩
//?var_dump($result);break;
if($result){
echo??1;
}else{
echo?0;
}
}
}
錯(cuò)誤描敘清楚
$sql="select * from xh_article";
$res=mysql_query($sql);
echo $res;
----
echo 肯定不行了 var_dump
echo 只能輸出 字符串 數(shù)字 之類的 不能輸出數(shù)組 對(duì)象
親!你把127.0.0.1換成 localhost, 然后在看一下行否!如果換不行的話可能是你的Apache沒有開啟! 你可以到這個(gè)網(wǎng)站上看一下PHP數(shù)據(jù)庫的連接! 希望能夠幫到你!