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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:35:42+00:00 2026-05-28T00:35:42+00:00

What I would like to ‘have’ is someway to export my tables including the

  • 0

What I would like to ‘have’ is someway to export my tables including the foreign keys. And whenever/whereever re-execute those create table queries.

The problem I am facing though is making sure the right preconditions exist per table.

if table B references A and A references C. Then first C must be created, then A and at last B.

But creating the right order is something that I do not know how to do (yet).

I am currently creating the queries this way: (not the complete code)

class DBManager{
    private function createSQLCreateTableDump(){
        $query = "SHOW TABLES";
        $res = $this->db->prepare($query)->fetchObjectAll();
        foreach( $res as $table){
            $this->createSQLCreateTableQuery(current(get_object_vars($table)));
        }
    }

    private function createSQLCreateTableQuery($tableName){
        $query = "SHOW CREATE TABLE {$tableName}";
        $res = $this->db->prepare($query)->fetchObjectOnce();

        return $res->{"Create Table"};
    }
}

As a reference, $this->db is a class named Database which extends PDO.
fetchObjectOnce and fetchObjectAll returns each row returned as an object. The first argument (which I am not using here) specifies the class type returned. Else stdClass is used.

current(get_object_vars($table)) is used to get the first column returned. Because the column names differ per database used. This seemed the fastest/easiest way.

The problem with this method is that some tables with constraints will be created before the constraint can be created.

the question: What would be a good solution to this problem?

Just thought of this: (which I will try to work out).
I can get the constraints themself from the informatino_schema.table_constraints and key_column_usage tables. Thus I can create a tree of dependancies. Will see how far I can come that way.

  • 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-28T00:35:43+00:00Added an answer on May 28, 2026 at 12:35 am

    Right, I’ve answered my own question and provided an example:

    http://pastebin.com/5dg6B0ZF

    it is not the cleanest of my work, but it works so far.

    it creates two temporary arrays.

    One holding the references per table, the other the queries.
    I am using table names as keys for the arrays for easy searching.

    I won’t accept my own answer till somewhere tomorrow to see if someone else comes up with a better solution.

    Let me know what you think.

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

Sidebar

Related Questions

would like to know how can this be implemented in Joomla. I have a
would like to put fieldSets side-by-side on my Edit page because I have so
Would like to know what does Drupal 7 and Acquia have in common? I
Would like to have an executable save its state by modifying its own global
would like to have a central place to register new signals, connect to signals,
Would like to ask for advice. there is a need for binary to have
Would like to know is that possible to have filter with default value with
I would like to generate periodical reports and have them sent to the users.
Would like to parse IPv4 address from exit-addresses . Format of the file: ExitNode
Would like a for loop in jquery so that: For every hover_link: show hidden

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.