-3

i have this 3 class

"Fatal error: Call to undefined function bluesoft\connect() in C:\wamp\www\class\utility\DataBase.php on line 43"

1-database file

<?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- index

    <?php

include "class/utility/User.php";



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

?>
2
  • 2
    possible duplicate of PHP Call to undefined function Commented Sep 14, 2015 at 8:49
  • i will read all Call to undefined function .. thanks Commented Sep 14, 2015 at 9:02

1 Answer 1

0

connect() is not a global function so you need to use it with object reference so

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

the $this is the current object.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.