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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:03:32+00:00 2026-05-13T23:03:32+00:00

I have a script that parse the database and create php classes to work

  • 0

I have a script that parse the database and create php classes to work with that db. (zend-db-model-generator). is there a way to in php to have a DBMS agonstic commands so on each type of db it will return the table structure ?

so it doesn’t matter if i use the pdo driver once for mysql and once for postgresql, it will still return the table structure.

the only solution that i see for now is to get the db type and to switch on each db type and execute the appropriate command.

  • 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-13T23:03:33+00:00Added an answer on May 13, 2026 at 11:03 pm

    Using the same SQL query, unfortunatly, doesn’t seem quite possible, as far as I can tell…

    About your idea of going through the database to extract informations about each table to generate some PHP classes, that’s one of the things that Doctrine (the most famous PHP ORM) does.

    If you download it, and take a look at the classes in Doctrine/Import/[DatabaseType].php, you’ll see this is done differently for each kind of database.

    For instance, for MySQL, the following piece of code is used in Doctrine_Import_Mysql :

    'listTableFields' => 'DESCRIBE %s',
    

    On the other hand, for PostgreSQL, you’ve got the following, in Doctrine_Import_Pgsql :

    'listTableColumns'     => "SELECT
                                a.attnum,
                                a.attname AS field,
                                t.typname AS type,
                                format_type(a.atttypid, a.atttypmod) AS complete_type,
                                a.attnotnull AS isnotnull,
                                (SELECT 't'
                                  FROM pg_index
                                  WHERE c.oid = pg_index.indrelid
                                  AND a.attnum = ANY (pg_index.indkey)
                                  AND pg_index.indisprimary = 't'
                                ) AS pri,
                                (SELECT pg_attrdef.adsrc
                                  FROM pg_attrdef
                                  WHERE c.oid = pg_attrdef.adrelid
                                  AND pg_attrdef.adnum=a.attnum
                                ) AS default
                          FROM pg_attribute a, pg_class c, pg_type t
                          WHERE c.relname = %s
                                AND a.attnum > 0
                                AND a.attrelid = c.oid
                                AND a.atttypid = t.oid
                          ORDER BY a.attnum",
    

    Not that easy, it seems ^^

    And, farther down each class, there is a method called listTableColumns — which is not the same for each database type…

    So I’m guessing things will, unfortunatly, not be as simple as you hoped…

    But, as a sidenote : maybe you could use Doctrine for that part of your project — might be faster than re-inventing the wheel 😉

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

Sidebar

Ask A Question

Stats

  • Questions 377k
  • Answers 377k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer [repeatbutton setImage:[UIImage imageNamed:@"repeatselected.png"] forState:UIControlStateSelected]; Are you also setting the button… May 14, 2026 at 8:55 pm
  • Editorial Team
    Editorial Team added an answer Just chmod go-w /opt/local/bin at a shell prompt (depending on… May 14, 2026 at 8:55 pm
  • Editorial Team
    Editorial Team added an answer This is my preferred solution: public static Long getFileSize(String path)… May 14, 2026 at 8:55 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.