| Index
» Projects
» phpMyEdit
» Forum
» Create table if Not exists? |
 |
markeh
Joined: 16 Mar 2012
Posts: 2
Posted: 2012-03-16 03:03
Back to top
Reply with quote
|
Hi,
This may be a completely stupid question, but is there an easy way to create a table if not exists before phpmyedit is called. So that if I want to use the phpmyedit files with a different database, the tables will be created for me.
I was thinking of something like this below, to test if a table is there and create it if necessary then put everything else in a function phpmyeditStart();
$dbName = 'NAME_OF_DATABASE';
$sql ='SHOW TABLES WHERE Tables_in_' . dbName . ' = \'' . $tableName . '\'';
$rs = mysql_query($sql);
if(!mysql_fetch_array($rs))
create table...
phpmyeditStart();
else
phpmyeditStart();
Any advice would be great.
|
markeh
Joined: 16 Mar 2012
Posts: 2
Posted: 2012-03-16 04:24
Back to top
Reply with quote
|
Just tried the above and it works alright, I don't see any problems doing it that way. I'm just wondering if anyone else does.
It probably seems a little pointless but it's for a university thing so I can work on it at home and uni without having to recreate all the tables manually.
|
doug
Joined: 10 Feb 2003
Posts: 1013
Location: Denver, Colorado (USA)
Posted: 2012-03-16 18:18
Back to top
Reply with quote
|
if installed in both locations, phpMyAdmin's Export and Import functions may offer less risk, while affording the opportunity to save exports using dated file names, such that if something unexpected happens and data is compromised or a table crashes then you have multiple backups to choose from.
If a table crashes and cannot be repaired and there are no backups then you have a real problem. Tables do crash from time to time, due to power outages and all sorts of unexpected events. On 100 websites that I work on, about 2-3 tables crash each year. I have a cron job running on each site which backs up all the tables each night, saving exports for 1 week before deleting them, and emailing an export to a Gmail account each week. Better safe than sorry.
|
|
Post new topic
Reply to topic
|
|
|
|