Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

returning a variable fom function does not work.

variable php dao function

  • Please log in to reply
6 replies to this topic

#1 Dorgon

Dorgon

    CC Regular

  • Member
  • PipPipPip
  • 37 posts

Posted 17 October 2012 - 05:45 AM

Hello guys,

Ik have a small question, I am currently working on a project.
At this moment I have the domain classes and I am working on the DAO factory at the moment.

let's say I have a class MYSQLStudentDAO, in this class I create functions for the domain class student to load, save, update... in an MYSQL database.
The MYSQLStudentDAO class extends DBObject and implements IStudentDAO.
DBObject can create and close a connection.
IStudentDAO is the Interface of the domain class Student.

Now all the classes are made I can start making the actual querrys and stuff.
So now I got my first function ready: loadStudent()
It is all standard: just a querty with some info to find the student in the database.., get all the info and create a new object of Student.

But when I want to use the object on my webpage it says that the variable is not declared?!?!
So I made this:
public function loadStudent(Student $Student){
$querry =
"
SELECT * FROM 'gebruiker'
";
$result = 'test';
if(!$result) {
die("Dufaq, geen connectie:" . mysql_error);

} else return $result;
}
Now result always has the value "test" and it should be returned.

now on my test webpage i do this:

$DAOFactory = new MYSQLDAOFactory();
$DAOFactory->setCurrentFactory($DAOFactory);
$Voornaam = 'William';
$Achternaam = 'Praat';
$TussenVoegsel = '';
$Wachtwoord = 'test';
$Email = 'william_praat@hotmail.com';
$Geslacht = true;
$OVnummer = 105778;
$SESSION['CurrentStudent'] = new Student($Voornaam, $Achternaam, $TussenVoegsel, $Wachtwoord, $Email, $Geslacht, $OVnummer);
echo $SESSION['CurrentStudent']->getOVnummer();
$SESSION['CurrentStudent']->loadStudent($SESSION['CurrentStudent']);
echo $result

now I get this error:

105778
Notice: Undefined variable: result in C:\xampp\htdocs\BKS\Webpages\test.php on line 33

what do I need to do to get the variable fom my function to my webpage???
Thanks in advance!
  • 0

#2 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 17 October 2012 - 05:51 AM

$result as a symbol ONLY exists inside of loadStudent. Try changing your code to this:
$DAOFactory = new MYSQLDAOFactory();
$DAOFactory->setCurrentFactory($DAOFactory);
$Voornaam = 'William';
$Achternaam = 'Praat';
$TussenVoegsel = '';
$Wachtwoord = 'test';
$Email = 'william_praat@hotmail.com';
$Geslacht = true;
$OVnummer = 105778;
$SESSION['CurrentStudent'] = new Student($Voornaam, $Achternaam, $TussenVoegsel, $Wachtwoord, $Email, $Geslacht, $OVnummer);
echo $SESSION['CurrentStudent']->getOVnummer();
echo $SESSION['CurrentStudent']->loadStudent($SESSION['CurrentStudent']);

  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#3 Dorgon

Dorgon

    CC Regular

  • Member
  • PipPipPip
  • 37 posts

Posted 17 October 2012 - 05:56 AM

When I do that nothing happens, it just shows the getOVnummer();
  • 0

#4 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 17 October 2012 - 06:02 AM

Try posting the complete code needed to reproduce the problem. You've posted bits and pieces of code, but not something anyone can easily dupe the problem with.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#5 Dorgon

Dorgon

    CC Regular

  • Member
  • PipPipPip
  • 37 posts

Posted 17 October 2012 - 06:11 AM

Ok, ill post of what I think is needed:
<?php

/*
    De constructor werkt.
    Getters en Setters werken.
    interface geeft geen problemen.
*/
require_once '../Interfaces/IGebruikerDAO.php';
abstract class Gebruiker implements IGebruikerDAO{
    public $Voornaam;
    public $Achternaam;
    public $TussenVoegsel;
    public $Wachtwoord;
    public $Email;
    public $Geslacht;
    
    public function setVoornaam($Voornaam){
        $this->Voornaam = $Voornaam;
    }
    
    public function getVoornaam(){
        return $this->Voornaam;
    }
    
    public function setAchternaam($Achternaam){
        $this->Achternaam = $Achternaam;
    }
    
    public function getAchternaam(){
        return $this->Achternaam;
    }
    
    public function setTussenVoegsel($TussenVoegsel){
        $this->TussenVoegsel = $TussenVoegsel;
    }
    
    public function getTussenVoegsel (){
        return $this->TussenVoegsel;
    }
    
    public function setWachtwoord($Wachtwoord){
        $this->Wachtwoord = $Wachtwoord;
    }
    
    public function getWachtwoord(){
        return $this->Wachtwoord;
    }
    
    public function setEmail($Email){
        $this->Email = $Email;
    }
    
    public function getEmail(){
        return $this->Email;
    }
    
    public function setGeslacht($Geslacht){
        $this->Geslacht = $Geslacht;
    }
    
    public function getGeslacht(){
        return $this->Geslacht;
    }
    
    //hier word methode update aangeroepen
    public function saveGebruiker(Gebruiker $Gebruiker){
    
    }
    //hier word methode load aangeroepen
    public function updateGebruiker(Gebruiker $Gebruiker){
    
    }
    //hier word methode delete aangeroepen
    public function deleteGebruiker(Gebruiker $Gebruiker){
    
    }
    //hier word methode insert aangeroepen
    public function loadGebruiker(Gebruiker $Gebruiker){
    
    }
    //alle objecten downloaden
    public function loadAllGebruikers(){
    
    }
    
}
?>

<?php
/*
    De constructor werkt.
    Getters en Setters werken.
    interface geeft geen problemen.
*/
require_once 'Gebruiker.php';
include '../Interfaces/IStudentDAO.php';

class Student extends Gebruiker implements IStudentDAO{
    public $OVnummer;
    public $BewijwkaartenVanStudent;

    public function Student($Voornaam, $Achternaam, $TussenVoegsel, $Wachtwoord, $Email, $Geslacht, $OVnummer){
    $this->Voornaam = $Voornaam;
    $this->Achternaam = $Achternaam;
    $this->TussenVoegsel = $TussenVoegsel;
    $this->Wachtwoord = $Wachtwoord;
    $this->Email = $Email;
    $this->Geslacht = $Geslacht;
    $this->OVnummer = $OVnummer;
    }
    
    public function setOVnummer($OVnummer){
        $this->OVnummer = $OVnummer;
    }
    
    public function getOVnummer(){
        return $this->OVnummer;
    }
    /*
    public function CreateBewijskaart(){
        $Bewijskaart Bewijskaart = new Bewijskaart($Bewijskaartid, $BewijskaartNummer, $KorteBeschrijving, $Situatie, $Taak, $Aanpak, $Resultaat, $Reflectie);
    }
    */
    //hier word methode update aangeroepen
    public function saveStudent(Student $Student){
    
    }
    //hier word methode load aangeroepen
    public function updateStudent(Student $Student){
    
    }
    //hier word methode delete aangeroepen
    public function deleteStudent(Student $Student){
    
    }
    //hier word methode insert aangeroepen
    public function loadStudent(Student $Student){
    
    }
    //alle objecten downloaden
    public function loadAllStudenten(){
    
    }
}
?>

<?php
require_once('../Classes/Gebruiker.php');
interface IGebruikerDAO{
    public function saveGebruiker(Gebruiker $Gebruiker);
    public function updateGebruiker(Gebruiker $Gebruiker);
    public function deleteGebruiker(Gebruiker $Gebruiker);
    public function loadGebruiker(Gebruiker $Gebruiker);
    public function loadAllGebruikers();
}
?>

<?php
require_once('../Classes/Student.php');
interface IStudentDAO{
    public function saveStudent(Student $Student);
    public function updateStudent(Student $Student);
    public function deleteStudent(Student $Student);
    public function loadStudent(Student $Student);
    public function loadAllStudenten();
}
?>

<?php
// ALLE interfaces includen
foreach (glob("../../Interfaces/") as $Filename){
    require_once $Filename;
}
// eind

abstract class DAOFactory{
    private static $CurrentFacory;
    
    public static function getCurrentFacory(){
        return $this->$CurrentFactory;
    }
    
    public static function setCurrentFactory($Factory){
        $CurrentFactory = $Factory;
    }
    
    public static function getIAdminDAO(){
        return new IAdminDAO();
    }
    /*
    public abstract IAdminDAO getIAdminDAO();
    public abstract IBewijskaartDAO getIBewijskaartDAO();
    public abstract ICCPWDAO getICCPWDAO();
    public abstract ICompetentieClusterDAO getICompetentieClusterDAO();
    public abstract ICompetentieDAO getICompetentieDAO();
    public abstract IComponentDAO getIComponentDAO();
    public abstract IGebruikerDAO getIGebruikerDAO();
    public abstract IGewenstResultaatDAO getIGewenstResultaatDAO();
    public abstract IKerntaakDAO getIKerntaakDAO();
    public abstract IKwalificatieDAO getIKwalificatieDAO();
    public abstract ILeraarBegeleiderDAO getILeraarBegeleiderDAO();
    public abstract ILeraarDAO getILeraarDAO();
    public abstract IManagerDAO getIManagerDAO();
    public abstract IOpleidingsverantwoordelijkeDAO getIOpleidingsverantwoordelijkeDAO();
    public abstract IPrestatieIndicatorDAO getIPrestatieIndicatorDAO();
    public abstract IStudentDAO getIStudentDAO();
    public abstract IUitstroomDAO getIUitstroomDAO();
    public abstract IWerknemerDAO getIWerknemerDAO();
    public abstract IWerkprocesDAO getIWerkprocesDAO();
    */
}
?>

<?php
// ALLE interfaces includen
foreach (glob("../../Interfaces/") as $Filename){
    require_once $Filename;
}
// eind
require_once ('MYSQLStudentDAO.php');
require_once ('/../Utilities/DBObject.php');
class MYSQLDAOFactory extends DAOFactory{
    
    public static function getIAdminDAO(){
        return new MYSQLAdminDAO();
    }
    
    public function getIBewijskaartDAO(){
        return new MYSQLBewijskaartDAO();
    }
    
    public function getICCPWDAO(){
        return new MYSQLICCPWDAO();
    }
    
    public function getICompetentieCluster(){
        return new MYSQLCompetentieClusterDAO();
    }
    
    public function getICompetentieDAO(){
        return new MYSQLCompetentieDAO();
    }
    
    public function getIComponentDAO(){
        return new MYSQLComponentDAO();
    }
    
    public function getIGebruikerDAO(){
        return new MYSQLGebruikerDAO();
    }
    
    public function getIGewenstResultaatDAO(){
        return new MYSQLGewenstResultaatDAO();
    }
    
    public function getIKerntaakDAO(){
        return new MYSQLKerntaakDAO();
    }
    
    public function getIKwalificatieDAO(){
        return new MYSQLKwalificatieDAO();
    }
    
    public function getILeraarBegeleiderDAO(){
        return new MYSQLLeraarBegeleiderDAO();
    }
    
    public function getILeraarDAO(){
        return new MYSQLLeraarDAO();
    }
    
    public function getIManagerDAO(){
        return new MYSQLManagerDAO();
    }
    
    public function getIOpleidingsVerantwoordelijkeDAO(){
        return new MYSQLOpleidingsVerantwoordelijkeDAO();
    }
    
    public function getIPrestatieIndicatorDAO(){
        return new MYSQLPrestatieIndicatorDAO();
    }
    
    public function getIStudentDAO(){
        return new MYSQLStudentDAO();
    }
    
    public function getIuitstroomDAO(){
        return new MYSQLUitstroomDAO();
    }
    
    public function getIWerknemerDAO(){
        return new MYSQLWerknemerDAO();
    }
    
    public function getIWerkprocesDAO(){
        return new MYSQLWerkprocesDAO();
    }
}

?>

<?php
require_once ('../Utilities/DBObject.php');
require_once ('../../Classes/Gebruiker.php');
require_once ('../../Interfaces/IGebruikerDAO.php')
class MYSQLGebruikerDAO extends DBObject implements IGebruikerDAO{
    
    private static MYSQLGebruikerDAO $Instance;
    $Statement = null;
    $Rst - null;
    
    public static IGebruikerDAO getInstance(){
        if($Instance == null){
            $Instance = new MYSQLGebruikerDAO();
        }
        return $Instance
    }
    



    public function saveGebruiker(Gebruiker $Gebruiker){
        return null;
    }
    
    public function updateGebruiker(Gebruiker $Gebruiker){
        return null;
    }
    
    public function deleteGebruiker(Gebruiker $Gebruiker){
        return null;
    }
    
    public function loadGenruiker(Gebruiker $Gebruiker){
        return null;
    }
    
    public function loadAllGebruikers(){
        return null;
    }
}
?>

<?php
require_once ('/../Utilities/DBObject.php');
require_once ('/../../Classes/Student.php');
require_once ('/../../Interfaces/IStudentDAO.php');
class MYSQLStudentDAO extends DBObject implements IStudentDAO{

/*
    private static MYSQLGebruikerDAO $Instance;
        $Statement = null;
        $Rst - null;
    
    public static IGebruikerDAO getInstance(){
        if($Instance == null){
            $Instance = new MYSQLGebruikerDAO();
        }
        return $Instance
    }
*/
    public function saveStudent(Student $Student){
        
        
        
    }
    
    public function updateStudent(Student $Student){
        return null;
    }
    
    public function deleteStudent(Student $Student){
        return null;
    }
    
    public function loadStudent(Student $Student){
        $querry =
        "
        SELECT * FROM 'gebruiker'
        ";
        $result = 'test';
        if(!$result) {
            die("Dufaq, geen connectie:" . mysql_error);
            
        } else return $result;
    }    
    
    public function loadAllStudenten(){
        return null;
    }
}
?>
 

I hope you have enough information.
  • 0

#6 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 17 October 2012 - 06:35 AM

The code you posted does NOT ever call loadStudent. It does, however, have three versions of loadStudent, which raises the question: which version is being called? In particular, the version in Student (which you called in your previous code), does nothing at all.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#7 Dorgon

Dorgon

    CC Regular

  • Member
  • PipPipPip
  • 37 posts

Posted 17 October 2012 - 06:48 AM

aye it's true, the methods in the domain classes have to go, there are the interfaces for.
But to create a good DAO factory a class should have a interface and a DAO right?
  • 0





Also tagged with one or more of these keywords: variable, php, dao, function

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download