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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:19:18+00:00 2026-05-15T22:19:18+00:00

We are running a PHP (zend framework) app that creates a database per user

  • 0

We are running a PHP (zend framework) app that creates a database per user (for security/backup/and others reasons).
All these databases have exactly the same structure and that will always be the case. When we deploy new features we’ll need to expand all databases with the new fields/tables.

I’ve read about using dbdeploy for that, but I’m not sure that they support multiple databases at once (without giving in the names one by one). Databases are called user1, user2, user3 and so on.

Are there any good tools that will make this process for us a bit easier and less painful?
We are running phing for automated deployment and found the guide http://www.davedevelopment.co.uk/2008/04/14/how-to-simple-database-migrations-with-phing-and-dbdeploy/ not so useful because they don’t support multiple databases like we have.

Also, windows or mac mysql clients that can do this are possible for us, so we are open for anything

  • 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-15T22:19:19+00:00Added an answer on May 15, 2026 at 10:19 pm

    Here is a PHP script that I put together for you. It gets a list of all databases and applies the updates if the database name begins with user.

    I also have it backup each database before it applies the changes. The backup portion is specific to Linux/Unix right now, but it can be tweaked to work on other operating systems.

    It is pretty verbose at the moment, so you can change it as needed. You can also change the line terminator, depending if you will be running it from the CLI or a browser. I would suggest to put this in your scripts directory and run it from the CLI.

    Let me know if you need anything else or if this doesn’t work for you.

    <?php
    // Configure these as needed
    $db_host = 'localhost';
    $db_user = 'user';
    $db_pass = 'password';
    
    $datetime_pattern       = date('Ymd.His');
    $backup_file_path       = "/path/to/db_backups/$datetime_pattern/";
    $backup_file_format     = "db_backup.%s.sql";
    $backup_syntax_pattern  = "/usr/bin/mysqldump --host=%s --user=%s --password=%s --opt %s > $backup_file_path/db_backup.%s.sql";
    // !!!!!!!!!!!!!!!!!!!!!!!!!!!!
    // CHANGE THE PERMISSIONS!!!!!!
    // !!!!!!!!!!!!!!!!!!!!!!!!!!!!
    $backup_file_permission = 0777;
    
    // Choose how to terminate your lines
    $line_end = "\n";      // Use for CLI
    //$line_end = "<br/>";   // Use for browser
    
    // Match words that begin with 'user', case-insensitive
    $pattern = '/^user/i';
    
    // What changes will we be applying?
    $db_update_syntax = array("ALTER TABLE foo ADD baz1 VARCHAR(30) AFTER bar1",
                              "ALTER TABLE foo ADD baz2 VARCHAR(30) AFTER bar2",
                              "ALTER TABLE foo ADD baz3 VARCHAR(30) AFTER bar3",
                             );
    
    // END OF CONFIGURATION
    /////////////////////////////////////////////////////////////
    
    
    // Create the database backup directory
    if (!mkdir($backup_file_path, $backup_file_permission, true)) {
        die('Failed to create backup directory...');
    }
    
    // Connecting to MySQL.
    $conn = @mysql_connect($db_host, $db_user, $db_pass)
            or die('Not connected : ' . mysql_errno() . ': ' . mysql_error());
    
    $db_list = mysql_list_dbs($conn);
    
    echo "{$line_end}Starting Database Update.{$line_end}";
    while ($row = mysql_fetch_assoc($db_list)) {
        $db_name = $row['Database'];
        if (preg_match($pattern, $db_name)) {
            echo "{$line_end}A match was found: [$db_name]{$line_end}";
            echo "Backing up the database{$line_end}";
            // Backup the database
            $backup_syntax = sprintf($backup_syntax_pattern, $db_host, $db_user, $db_pass, $db_name, $db_name);
            exec($backup_syntax);
            $db_selected = mysql_select_db($db_name, $conn)
                           or die("Can't use [$db_name] : " . mysql_error());
    
            foreach ($db_update_syntax as $each_update_syntax) {
                echo "Altering using: [$alter_syntax]{$line_end}";
                $update_status = mysql_query($alter_syntax);
                if ($update_status) {
                    echo "Success!{$line_end}{$line_end}";
                } else {
                    echo "Unable to update [$db_name] : " . mysql_error() . "{$line_end}{$line_end}";
                }
            }
        } else {
            echo "Ignoring: [$db_name]{$line_end}";
        }
    }
    echo "Finished!{$line_end}";
    // Free resources / Close MySQL Connection
    mysql_free_result($db_list);
    mysql_close($conn);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 499k
  • Answers 500k
  • 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 You never access the sqlite database directly when using Core… May 16, 2026 at 1:49 pm
  • Editorial Team
    Editorial Team added an answer If you look at the patch-ahead documentation you will notice… May 16, 2026 at 1:49 pm
  • Editorial Team
    Editorial Team added an answer use timthumb, it will create thumbnails for you, you just… May 16, 2026 at 1:49 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

Related Questions

I have a website running using Zend Framework and am trying to setup Zend
All, I am working on a Zend Framework based web application. We keep encountering
Is it possible to have multiple versions of PHP running on the same box
I am using Zend Debugger to debug my php application built based on the
I managed to get Zend Studio 5.5.1 running on Windows 7 by running in
I'm running php vs. 4.1.14 on yahoo with phpMyAdmin. it says the file is
I have one big php application running on php 4 but I want to
For a recent project, I have a PHP script running as a CLI-based daemon.
relatively long-time PHP user here. I could install XAMPP in my sleep at this
I'm fairly new to Zend and am having some difficulties with creating my unit

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.