Page 1 of 1

Store query strings in a class

Posted: Mon Feb 15, 2010 10:20 am
by MCouche
Hello,

I am brand new to PHP with an ASP.Net background.
For a database driven application, I would like to save my query strings in a class.

I believe (!?) that the closest I came is shown below:
<?php

class EMail_Helper

{

var $Vets_Value = 'This will be the query...' ;

function Query_reports_to_email_vets()
{
return $this->Query_reports_to_email_vets=$Vets_Value;
}

}
?>

When instantiated, a call to the property return an empty string.

<?php // on instancie les classes
include('.....php');

$QueryHelper = new EMail_Helper();

echo $QueryHelper->Query_reports_to_email_vets();
?>

I would appreciate your support,

Michel

Re: Store query strings in a class

Posted: Mon Feb 15, 2010 10:47 am
by jkon
Hello,

I am a bit surprised that the property returned anything. Normally you should get “Notice: Undefined variable: Vets_Value in …….. on line 11”.

You return $this->Query_reports_to_email_vets=$Vets_Value; $Vets_Value doesn’t exist in this function. If you want to use $Vets_Value of the class just use $this-> Vets_Value and it will work but it is still not clear coding.

If you just want function Query_reports_to_email_vets just to return the value of $this-> Vets_Value then it is clearer to use return $this->Vets_Value;

Hope I helped a bit …

Re: Store query strings in a class

Posted: Mon Feb 15, 2010 10:47 am
by flying_circus
You are close!

Code: Select all

<?php
class EMail_Helper
{
  var $Vets_Value = 'This will be the query...';
 
  function Query_reports_to_email_vets()
  {
    return $this->Vets_Value;
  }
}
?>