我用打算用PHP写操作数据库的类 可是调用时出问题了 帮我看看
如下这样有问题
复制内容到剪贴板
代码:
<?php
class thl_Odb{
function connectionDB($thl_ip,$thl_users,$thl_password,$thl_bianma,$thl_data){
$conn=mysql_connect($thl_ip,$thl_users,$thl_password);
mysql_query("SET NAMES '".$thl_bianma."'");
mysql_select_db($thl_data);
}
function selectDB($thl_sql,$thl_rec){
$sql=mysql_query($thl_sql);
if($rs=mysql_fetch_object($sql)){
$rec=split(",",$thl_rec);
foreach ($rec as $v){
$selectDB[$v]=$rs->$v;
}
return $selectDB;
}else{
echo mysql_error();
}
}
function ODB($thl_sql,$thl_url){
if(mysql_query($thl_sql)){
echo ("<script>alert('删除成功!');location='".$thl_url."';</script>");
exit();
}else{
echo ("操作失败,原因未知!");
exit();
}
}
}
?>
<?php
$Odb=new thl_Odb;
$Odb->connectionDB("127.0.0.1","root","","utf-8","myweb");
$action=$_GET['action'];
switch ($action){
case "del":
del();
default:
lists();
}
function lists(){
$sql="select * from adminInfo where id=2";
$selectDB=$Odb->selectDB($sql,"id,users,password,super");
foreach($selectDB as $v){
echo $v."<br>";
}
echo "<a href='index.php?action=del&id=".$selectDB[id]."'>删除</a>";
}
function del(){
$Odb->ODB("delete from adminInfo where id=".$_GET['id']."","index.php");
}
?>这样却没问题
复制内容到剪贴板
代码:
<?php
class thl_Odb{
function connectionDB($thl_ip,$thl_users,$thl_password,$thl_bianma,$thl_data){
$conn=mysql_connect($thl_ip,$thl_users,$thl_password);
mysql_query("SET NAMES '".$thl_bianma."'");
mysql_select_db($thl_data);
}
function selectDB($thl_sql,$thl_rec){
$sql=mysql_query($thl_sql);
if($rs=mysql_fetch_object($sql)){
$rec=split(",",$thl_rec);
foreach ($rec as $v){
$selectDB[$v]=$rs->$v;
}
return $selectDB;
}else{
echo mysql_error();
}
}
function ODB($thl_sql,$thl_url){
if(mysql_query($thl_sql)){
echo ("<script>alert('删除成功!');location='".$thl_url."';</script>");
exit();
}else{
echo ("操作失败,原因未知!");
exit();
}
}
}
?>
<?php
$action=$_GET['action'];
switch ($action){
case "del":
del();
default:
lists();
}
function lists(){
$Odb=new thl_Odb;
$Odb->connectionDB("127.0.0.1","root","","utf-8","myweb");
$sql="select * from adminInfo where id=2";
$selectDB=$Odb->selectDB($sql,"id,users,password,super");
foreach($selectDB as $v){
echo $v."<br>";
}
echo "<a href='index.php?action=del&id=".$selectDB[id]."'>删除</a>";
}
function del(){
$Odb=new thl_Odb;
$Odb->connectionDB("127.0.0.1","root","","utf-8","myweb");
$Odb->ODB("delete from adminInfo where id=".$_GET['id']."","index.php");
}
?>这是什么原因啊
为什么把数据库连接写上面不行