Store query strings in a class

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MCouche
Forum Newbie
Posts: 3
Joined: Mon Feb 15, 2010 10:10 am

Store query strings in a class

Post 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
jkon
Forum Newbie
Posts: 16
Joined: Mon Feb 15, 2010 6:01 am

Re: Store query strings in a class

Post 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 …
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: Store query strings in a class

Post 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;
  }
}
?>
Post Reply