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 7722151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:05:55+00:00 2026-06-01T04:05:55+00:00

In the code given below, I am trying to modify it in such a

  • 0

In the code given below, I am trying to modify it in such a way that the db connection variables are used from a config file. This should make the password more secure as I can restrict the config file’s permissions.

Kindly let me know if there is a way by which I can modify the code to get the db variables from another file/config file?

class ActivitycodesCollection {
    var $list, $err, $sql;    
    // --- Private variables for database access
    var $_db_host = "######";
    var $_db_username = "######";
    var $_db_passwd = "######";
    var $_db_name = "######";
    function query ($where="") {
        mysql_pconnect ($this->_db_host, $this->_db_username, $this->_db_passwd);
        mysql_select_db ($this->_db_name);
        $where = "WHERE " . $where;
        $sql = "SELECT * FROM activitycodes $where";
        $result = mysql_query ($sql);
        $this->err = mysql_error();
        $this->sql = $sql;
        if (mysql_num_rows($result) > 0) {
            while (list($id) = mysql_fetch_array ($result)) {
                $this->list[$id] = new activitycodes($id);
            }
        }
    }
}

I tried including the config.ini file in this class/function but it threw an error like

unexpected T_VARIABLE, expecting T_FUNCTION
  • 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-06-01T04:05:56+00:00Added an answer on June 1, 2026 at 4:05 am

    Your code is hopelessly outdated.
    1) Don’t use var for properties, use private or protected.
    2) Don’t use mysql_* functions, use PDO.
    3) Don’t keep connection details inside the class. Just require PDO connection in constructor.
    4) Don’t trust any data outside your scope – don’t allow just write some untrusted text into your SQL query (you do it by $where variable).
    5) Read books. “PHP Objects, Patterns, and Practice” will help you now, and “Clean code” – little bit later.

    Example:

    class ActivitycodesCollection
    {
        private $list;
        private $PDO;
        private $table_name;
    
        public function __construct(\PDO $PDO, $table_name)
        {
            $this->PDO        = $PDO;
            $this->table_name = $table_name;
        }
    
        public function fetchByParameter($parameter)
        {
            $query = $this->PDO->prepare("SELECT `id` FROM `{$this->table_name}` WHERE "
                    ." some_field = :parameter");
            if (!$query)
            {
                return false;
            }
            if (!($query->execute(array(':parameter'=> $parameter))))
            {
                return false;
            }
    
            $results = $query->fetchAll(\PDO::FETCH_ASSOC);
            if (!empty($result))
            {
                foreach ($results as $result)
                {
                    $id              = $result['id'];
                    $this->list[$id] = new ActivityCodes($id);
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Technology Used:- Asp.Net 2.0 Code:- See Below Description:- hello code given below is working
Given the code below, how would you create/implement SR.h so that it produces the
I am trying to implement a function. My code is given below. I want
I'm trying to bind CheckedListbox's Cheched items to Combobox my code is given below
hi I am trying to fetch data from link as given below http://abovestress.com/app_stress/fetch_all_detail.php?task=fetchtimefromdateanduserid&track_date=2011-08-09&tracker_user_id=374 but
I am trying to parse the given below html code using lxml.html and using
In the code given below, I need to position the userid box in the
Hello friends i am running code given below which contains the setLogTimeEntery function and
How to know the Id of item I clicked? my code is given below:
I tried the following code in LINQPad and got the results given below: List<string>

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.