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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:17:01+00:00 2026-06-14T14:17:01+00:00

I’m trying to switch from procedural to OOP php, I can connect to a

  • 0

I’m trying to switch from procedural to OOP php, I can connect to a database and use it fine in procedural however after a few hours of head scratching, google searches and little tweaks/changes I concede defeat and conclude I must be missing something.

I have two files, my IDE marks that the syntax issue is apparently with the “function”‘s part of the first file (test.php) but I just can’t figure out what, does any body have any ideas? the two files are below. Sorry for the formatting but for some reason I can’t tab within this textarea.

I’m assuming its something to do with a lack of constructor. I’ve tried to add one in instead of the config function but I still have syntax issues. In documentation/tutorials I can find mention of constructors in the php and functions in the html but nothing seems to explain how they work together with an example.

Disclaimer: both files are surrounded by <?php ?> tags and I am not addressing security measures currently. Walk before you can run and all that. I’ve also tried to throw a doctype at the beginning of test.php and pad it with <html> <head> and <body> tags where appropriate but to no avail. Using Apache 2.2.22 and PHP 5.3.13.

// ------- Test.php start -------
include 'obj_lib.php';

$db = new database;
$db = function config('test', 'root', '', 'localhost');
$db = function connect();
$db = function test_database();
// ------- Test.php end -------

// ------- obj_lib.php start -------
class database
{
  private $username;
  private $password;
  private $database;
  private $server;
  private $db_handle;
  private $db_found;

   public function config($indatabase=null, $inusername=null, $inpassword=null, $inserver=null)
   {
   $this->username = $inusername;
   $this->password = $inpassword;
   $this->database = $indatabase;
   $this->server   = $inserver;
   }

   public function connect()
   {
   $this->db_handle = mysql_connect($this->server, $this->username, $this->password);
   $this->db_found = mysql_select_db($this->database, $this->db_handle);
   }

   public function test_database()
   {
   echo "$this->username"."$this->password"."$this->database"."$this->server"."$this->db_handle"."$this->db_found";
   }
 }
// ------- obj_lib.php end -------
  • 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-14T14:17:02+00:00Added an answer on June 14, 2026 at 2:17 pm
    $db = new database;
    $db = function config('test', 'root', '', 'localhost');
    $db = function connect();
    $db = function test_database();
    

    Should be

    $db = new database;
    $db->config('test', 'root', '', 'localhost');
    $db->connect();
    $db->test_database();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I have a view passing on information from a database: def serve_article(request, id): served_article
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all

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.