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
Store query strings in a class
Moderator: General Moderators
Re: Store query strings in a class
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 …
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 …
- flying_circus
- Forum Regular
- Posts: 732
- Joined: Wed Mar 05, 2008 10:23 pm
- Location: Sunriver, OR
Re: Store query strings in a class
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;
}
}
?>