小妹不会写类,各位高手看下
class data{
//连接数据库
function conn(){
mysql_connect("localhost","root",123) or die('数据库连接失败!'.mysql_error());
mysql_select_db("guestbook");
}
//匹配用户信息
function selGuest($name,$password){
$query="select * from guest where name='$name' and password='$password'";
mysql_query("SET NAMES utf8");
$resSel=mysql_query($query);
}
}
在调用的时候该怎么办呢?我要$resSel
$data=new data;
$data->selGuest($name,$password);
可是$resSel该怎么得到啊?
class data{
//连接数据库
function conn(){
mysql_connect("localhost","root",123) or die('数据库连接失败!'.mysql_error());
mysql_select_db("guestbook");
}
//匹配用户信息
function selGuest($name,$password){
$query="select * from guest where name='$name' and password='$password'";
mysql_query("SET NAMES utf8");
$resSel=mysql_query($query);
}
}
在调用的时候该怎么办呢?我要$resSel
$data=new data;
$data->selGuest($name,$password);
可是$resSel该怎么得到啊?
function selGuest($name,$password){
$query="select * from guest where name='$name' and password='$password'";
mysql_query("SET NAMES utf8");
$resSel=mysql_query($query);
return $resSel;
}调用:
$data=new data;
$resSel = $data->selGuest($name,$password);
function selGuest($name,$password){
$query="select * from guest where name='$name' and password='$password'";
mysql_query("SET NAMES utf8");
return $resSel=mysql_query($query);
}
你要把这个返回后,就可以这样取值了$result = $data->selGuest($name,$password);
新增一个参数接收sql语句,这样更灵活了