PHP implementation of user query class instance _php skills

Source: Internet
Author: User

This example describes the user query class for PHP implementations. Share to everyone for your reference. The implementation method is as follows:

<?php class User {var $usertable;  function Get_oneuser ($field, $value) {$field _array=array ("id", "name");
    Query mode if (In_array ($field, $field _array)) {$sql = "select * from ' $this->usertable ' WHERE $field = ' $value '";
    $DB =new database;
    $res = $db->execute ($sql);
    $obj _user=mysql_fetch_object ($res);
   return $obj _user;
  else echo "Query method is wrong";
   function Get_moreusers () {Global $db;
   $argnums =func_num_args ();
   $argarr =func_get_args ();
     Switch ($argnums) {case 0: $sql = "select * from ' $this->usertable '";
    Break
     Case 2: $sql = "select * from ' $this->usertable ' WHERE $argarr [0]= ' $argarr [1] '";
    Break
     Case 4: $sql = "select * from ' $this->usertable ' WHERE $argarr [0]= ' $argarr [1] ' and $argarr [2]= ' $argarr [3] '";
   Break
   }//$db =new database;
   $res = $this->execute ($sql);
   $obj _arr=array ();
   while ($obj =mysql_fetch_object ($res)) {$obj _arr[]= $obj;
  return $obj _arr; }
 }?>

 

I hope this article will help you with your PHP programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.