用PHP检索mysqli对象变量

时间:2014-11-14 12:00:38

标签: php mysqli

我想连接到我的mysqli数据库服务器,然后分别连接到数据库...我的代码是:

//Initiate Contacts class
$Auth = new authenticate();
if(isset($_SESSION['DBcxn']) && empty($this->DbInfo))
{
    foreach($_SESSION['DBcxn'] as $DbFields=>$Vals)
    {
        if($DbFields == 'info')
        {
            $this->DbInfo = $Vals;
            if(!empty($this->DbInfo) && $this->DbInfo != NULL)
            {
                break;
            }
            else
            {
                //Initiate dB class
                $this->main = '<h4>Connect <strong>2</strong> a Database </h4>';
                $dB = new MySQLDB();
                $this->main .= $dB->show;                           
            }
        }
    }

MySQL连接类,它连接到数据库并设置SESSION变量......

private $dbUser = 'root';//
private $dbHost = 'localhost';
private $dbPass = '';//
private $dbDName = 'My_db';
public $show;

public function __construct()
{
    if(!isset($_SESSION['DBcxn']) or empty($_SESSION['DBcxn']->DbInfo)) {

    if (!$cxn = mysqli_connect("$this->dbHost","$this->dbUser","$this->dbPass"))
    {
        echo "Can not connect to MySQL Server";
        exit;
    }
    elseif(isset($_SESSION['WorkDbTable']))
        {
            $show = 'Work table is: '.$_SESSION['WorkDbTable'];
            $this->show = $show;
        }
        elseif(!isset($_SESSION['WorkDbTable']))
        {
            $show = '
            <form id="Connect2DbForm" method="post" action="'.$_SERVER['REQUEST_URI'].'">
            Select a Database to continue<br>
            <div class="btn-lg" >
            From data here
            </form>
            ';
            $this->show = $show;
        }

    }

}

从这里我可以更有效地使用该应用程序但是这个问题没有帮助... 我正在燃烧不必要的时间,请帮忙......我确定我只是错过了一些

0 个答案:

没有答案