开发者

OOP Query function

I'm sorry if this may sound like a really dumb question but I'm just beginning the grasp the concept of object oriented programming and I am kind of confused about the singleton pattern for php.

How would I incorporate a query along with saving the results from the rows fetched saved as variables into the singleton pattern?

For example, how would the code below get incorporated?

$query = "SELECT * FROM members WHERE email=   '".mysql_real_escape_string($_SESSION['email1'])."'";
$result   = mysql_query($query) or die(mysql_error());
$number   = mysql_num_rows($result);
$i   = 0;

while ($i < $number) 
{

    $first_name  = mysql_result($result,$i,"first_name"); 
    $last_name  = mysql_result($result,$i,"last_name");
    $state   = mysql_result($result,$i,"home_state");
    $id_district  = mysql_result($result,$i,"district");
    $political_views = mysql_result($result,$i,"political_views");
    $first_issue  = mysql_result($result,$i,"first_issue");
    $second_issue  = mysql_result($result,$i,"second_issue");
    $third_issue  = mysql_result($result,$i,"third_issue");
    $email   = mysql_result($result,$i,"email");
    $iStand   = mysql_result($result,$i,"iStand");
    $photo   = mysql_result($result,$i,"photo");
    $code   = mysql_result($result,$i,"code");
    $changed   = mysql_result($result,$i,"changed");
    $mem_ID          = mysql_result($result,$i,"member_ID");
    $pass   = mysql_result($result,$i,"password");
    $privacy   = mysql_result($result,$i,"privacy");
    $since   = mysql_result($result,$i,"inv开发者_StackOverflowite_date");
    $nombre   = mysql_result($result,$i,"peer_name");

    $i++;
  }


A Singleton pattern has a specific purpose:

the singleton pattern is a design pattern used to implement the mathematical concept of a singleton, by restricting the instantiation of a class to one object. This is useful when exactly one object is needed to coordinate actions across the system

This isn't appropriate for the functionality that you've presented above.

A Singleton pattern would be used, for example, when creating a system-wide settings class. The Singleton prevents itself from being instantiated more than once (or, at all) and instead provides a single place to get and set setting information.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜