Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 903063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:48:58+00:00 2026-05-15T15:48:58+00:00

I am trying to get a users ID from a database within a class,

  • 0

I am trying to get a users ID from a database within a class, but I have very little to no experience with classes, how could I go about getting the uid from the DB and then return the uid?

so basically something like this,

class hello {
   public function getUid(){
      //connect to the db
      //get all of the users info
      $array = mysql_fetch_array($result);
      $uid = $array['uid'];

      return $uid;
   }
}

Like I said, I am still new to classes, so any advice or help would be greatly appreciated!

Thanx in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T15:48:59+00:00Added an answer on May 15, 2026 at 3:48 pm

    First build a MySQL class library… suiting the requirements like in this sample piece:

    <?php
    
    include '../config/Dbconfig.php';
    
    class Mysql extends Dbconfig {
    
        public $connectionString;
        public $dataSet;
        private $sqlQuery;
        
        protected $databaseName;
        protected $hostName;
        protected $userName;
        protected $passCode;
    
        function Mysql() {
            $this -> connectionString = NULL;
            $this -> sqlQuery = NULL;
            $this -> dataSet = NULL;
    
            $dbPara = new Dbconfig();
            $this -> databaseName = $dbPara -> dbName;
            $this -> hostName = $dbPara -> serverName;
            $this -> userName = $dbPara -> userName;
            $this -> passCode = $dbPara ->passCode;
            $dbPara = NULL;
        }
      
        function dbConnect()    {
            $this -> connectionString = mysql_connect($this -> serverName,$this -> userName,$this -> passCode);
            mysql_select_db($this -> databaseName,$this -> connectionString);
            return $this -> connectionString;
        }
    
        function dbDisconnect() {
            $this -> connectionString = NULL;
            $this -> sqlQuery = NULL;
            $this -> dataSet = NULL;
            $this -> databaseName = NULL;
            $this -> hostName = NULL;
            $this -> userName = NULL;
            $this -> passCode = NULL;
        }
    
        function selectAll($tableName)  {
            $this -> sqlQuery = 'SELECT * FROM '.$this -> databaseName.'.'.$tableName;
            $this -> dataSet = mysql_query($this -> sqlQuery,$this -> connectionString);
            return $this -> dataSet;
        }
    
        function selectWhere($tableName,$rowName,$operator,$value,$valueType)   {
            $this -> sqlQuery = 'SELECT * FROM '.$tableName.' WHERE '.$rowName.' '.$operator.' ';
            if($valueType == 'int') {
                $this -> sqlQuery .= $value;
            }
            else if($valueType == 'char')   {
                $this -> sqlQuery .= "'".$value."'";
            }
            $this -> dataSet = mysql_query($this -> sqlQuery,$this -> connectionString);
            $this -> sqlQuery = NULL;
            return $this -> dataSet;
            #return $this -> sqlQuery;
        }
    
    
        function insertInto($tableName,$values) {
            $i = NULL;
    
            $this -> sqlQuery = 'INSERT INTO '.$tableName.' VALUES (';
            $i = 0;
            while($values[$i]["val"] != NULL && $values[$i]["type"] != NULL) {
                if($values[$i]["type"] == "char") {
                    $this -> sqlQuery .= "'";
                    $this -> sqlQuery .= $values[$i]["val"];
                    $this -> sqlQuery .= "'";
                }
                else if($values[$i]["type"] == 'int') {
                    $this -> sqlQuery .= $values[$i]["val"];
                }
                $i++;
                if($values[$i]["val"] != NULL)  {
                    $this -> sqlQuery .= ',';
                }
            }
            $this -> sqlQuery .= ')';
            #echo $this -> sqlQuery;
            mysql_query($this -> sqlQuery,$this ->connectionString);
            return $this -> sqlQuery;
            #$this -> sqlQuery = NULL;
        }
    
        function selectFreeRun($query) {
            $this -> dataSet = mysql_query($query,$this -> connectionString);
            return $this -> dataSet;
        }
    
        function freeRun($query) {
            return mysql_query($query,$this -> connectionString);
        }
    }
    ?>
    

    and the configuration file…

    <?php
    class Dbconfig {
        protected $serverName;
        protected $userName;
        protected $passCode;
        protected $dbName;
    
        function Dbconfig() {
            $this -> serverName = 'localhost';
            $this -> userName = 'root';
            $this -> passCode = 'pass';
            $this -> dbName = 'dbase';
        }
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get all the users information from the database and check
I'm trying to get a drop-down box to populate from data within a database,
I'm trying to get a list of all the users from users table and
I am trying to get all group members from Domain Users. When using AD
I am trying following, 1. Get response using Ajax from the users selection which
I have trouble with my app, when i'm trying to get active user from
I'm trying to get a count of users who have paid for a service
I'm trying to get user GUID from Active Directory. My code: DirectoryEntry entry =
I am trying to get the value user selected from search prompt and pass
I'm trying to get the text from a textbox as a user types, so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.