Forum Moderators: open

Message Too Old, No Replies

updating database tables when tables may or may not have changed?

updating database tables when tables may or may not have changed?

         

Tim_Mousel

10:23 pm on May 21, 2006 (gmt 0)

10+ Year Member



I have an update script for a script I wrote. Users will need to run the update script to add new tables and to alter tables.

Currently my install script pulls all of the create table statements from an sql file and creates the tables.

What is the best way to detect which tables are present and which are present but need to be altered?

I'm currently using this but that doesn't take care of adding alter statements:

if(!sql_result3)
{
if(mysql_errno() == 1062)
{
$errors[] = 'Duplicate entry, proceeding to next record...<br />';
}
if(mysql_errno() == 1060)
{
$errors[] = 'Duplicate column entry, proceeding to next record...<br />';
}

else {
die(sprintf("Couldn't execute query, %s: %s", db_errno(), db_error()));

}
}

Thanks,

Tim

[edited by: txbakers at 2:11 pm (utc) on May 22, 2006]
[edit reason] no URL signatures, please per TOS [/edit]

physics

5:10 pm on May 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can use SHOW TABLES to see what tables exist and compare to which ones should be there:
[dev.mysql.com...]

You can use DESCRIBE to see if that table still has the right structure
[dev.mysql.com...]