致命错误:在第43行的C:\ wamp \ www \ class \ utility \ DataBase.php中调用未定义的函数bluesoft \ connect()

时间:2015-09-14 08:48:16

标签: php

我有这3级

  

“致命错误:在第43行的C:\ wamp \ www \ class \ utility \ DataBase.php中调用未定义的函数bluesoft \ connect()”

1个数据库文件

<?php


    namespace bluesoft;

     class DataBase {

    public  function  __construct()
    {
        echo "1";
    }


    public   function Connect()
            {
                $servername = "localhost";
                $username = "root";
                $password = "";

                try {
                    $conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password);
                    // set the PDO error mode to exception
                    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                    return 1;
                }
                catch(PDOException $e)
                {
                    return 2;
                }


            }


    public function TestConnect()
           {
               if(!connect() == 1)
               {
                   echo"connect error";
               }

           }


} 


and

2-User file

<?php


    namespace bluesoft\User;
    use bluesoft\DataBase as am;
    include("DataBase.php");

    class User extends am{
    public  $User_id;
    private $User_name;
    private $User_email;
    private $User_pass;
    private $User_per;
    private $User_date;
    private $User_lldate;
    private $User_act;


    public function __construct()
    {

        $z= new am();
        $z->TestConnect();
    }


    public function add()
    {


    }

3-指数

    <?php

include "class/utility/User.php";



$a = new bluesoft\User\User();
$a->User_id =1;

?>

1 个答案:

答案 0 :(得分:0)

connect()不是全局函数,因此您需要将它与对象引用一起使用

public function TestConnect()
{
    if(!$this->connect() == 1)
    {
        echo"connect error";
    }
}

$this是当前对象。