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

  • SEARCH
  • Home
  • 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 592213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:42:59+00:00 2026-05-13T15:42:59+00:00

I have a class that extends PDO to give it the ability to pull

  • 0

I have a class that extends PDO to give it the ability to pull the configuration from an xml file. Unfortunately the our hosting provider has disabled SimpleXML so I need to refactor my code to use Dom, which is available.

I am using the following code:

class xmlPDO extends PDO
{
    public function __construct($xml_uri){
        $xml = simplexml_load_file($xml_uri);
        $dsn_template = "%s:host=%s; dbname=%s";
        $dsn = sprintf($dsn_template, $xml->dsn->driver, $xml->dsn->host, $xml->dsn->dbname);
        parent::__construct($dsn, $xml->username, $xml->password);
    }
}

To read the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE database [
<!ELEMENT database (name, description, dsn, username, password)>
    <!ELEMENT name (#PCDATA)>
    <!ELEMENT description (#PCDATA)>
    <!ELEMENT dsn (driver, dbname, host)>
        <!ELEMENT driver (#PCDATA)>
        <!ELEMENT dbname (#PCDATA)>
        <!ELEMENT host (#PCDATA)>
    <!ELEMENT username (#PCDATA)>
    <!ELEMENT password (#PCDATA)>
]>

<database>
    <name>Test Database</name>
    <description>Localhost test database, use only for testing</description>
    <dsn>
        <driver>mysql</driver>
        <dbname>test</dbname>
        <host>localhost</host>
    </dsn>
    <username>user</username>
    <password>test</password>
</database>

I am looking at the php.net documentation and am having a really hard time trying to figure out how I am supposed to be doing this. I can’t seem to be any clear code examples of pulling out data like this.

  • 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-13T15:42:59+00:00Added an answer on May 13, 2026 at 3:42 pm

    Or I could use the simple xml for php 4 class that behaves pretty much as simple xml, but works when simple-xml is disabled.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a class that extends the PDO class. it's called Database. but in
If I have a base class such that public abstract class XMLSubscription <T extends
I have a few classes such that: public class XMLStatusMessage extends XMLMessage {} public
I have a class that processes a 2 xml files and produces a text
I am having a class that extends View. I have another class that extends
I have a custom class that I've written that extends ImageView (for Android Java).
I have a class that extends JFrame to make orders. in the middle I
I have a class that extends AppWidgetProvider that provides the content for my widget.
I have written a class that extends JCheckBox and am now looking to override
I have a User class and an Author class that extends User. I have

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.