如何在php中切换连接文件?我有两个名为connection.php 和connection1.php 的数据库。当我提交用户名和密码时,我想检查第一个数据库,然后如果结果为空,则需要切换另一个数据库。但现在它只连接第一个数据库而不是第二个...我试图先关闭但它不起作用。请建议我任何解决方案...
enter code here
if(!empty($_POST['uname']) && !empty($_POST['pwd']))
{
$flag=0;
if($flag==0)
{
require_once('connection1.php');
$q="select * from user_login where (u_name='".$_POST['uname']."' or eid='".$_POST['uname']."') and password='".$_POST['pwd']."' and status=1";
//echo $q;
$res=mysql_query($q);
$row=mysql_fetch_assoc($res);
}
if(empty($row))
{
$flag=1;
mysql_close($res);
}
if($flag==1)
{
require_once('connection.php');
$q1="select * from user_login where (u_name='".$_POST['uname']."' or eid='".$_POST['uname']."') and password='".$_POST['pwd']."' and status=1";
$res1=mysql_query($q1);
//echo "Database : ".mysql_db_name($res1);
$row1=mysql_fetch_assoc($res1);
}
}
if(!empty($row))
{
$u_id=$row['u_id'];
//header("location:../index.php");
echo "<script>parent.location='Test.php'</script>";
}
else if(!empty($row1))
{
$u_id=$row1['u_id'];
//header("location:../index.php");
// print_r($row1);
echo "<script>parent.location='Test1.php'</script>";
}
else
{
$err = "<font color='red'>Incorrect Login Information</font>";
}
这是连接文件:-
enter code here
error_reporting(0);
$app="web";
if($app=="local")
{
define("SITEROOT", "http://".$_SERVER['HTTP_HOST']."/");
define("ABSPATH", "c://xampp/htdocs/ujjwal/");
define("SITEJS", "http://".$_SERVER['HTTP_HOST']."/js2/");
define("SITECSS", "http://".$_SERVER['HTTP_HOST']."/css/");
define("IMAGEDIR", "http://".$_SERVER['HTTP_HOST']."/images/");
define("UPIMAGEDIR", "http://".$_SERVER['HTTP_HOST']."/abcd/abcd/");
define(USR,'root');
define(DB,'xxxx');
define(HST,'localhost');
define(PWD,'');
} enter code here
else { define("SITEROOT", "http://".$_SERVER['HTTP_HOST']."/"); 定义("SITEJS", "http://".$_SERVER['HTTP_HOST']."/js2/"); 定义("SITECSS", "http://".$_SERVER['HTTP_HOST']."/css/"); 定义("IMAGEDIR", "http://".$_SERVER['HTTP_HOST']."/images/"); 定义("UPIMAGEDIR", "http://".$_SERVER['HTTP_HOST']."/zoombox_admin/"); 定义(USR,'abcdef');定义(数据库,'abcd');
定义(HST,'111.111.111.111');定义(密码,'xxx');} $con1=mysql_connect(HST,USR,PWD) or die ("connection failed"); $db=mysql_select_db(数据库,