0

I don't know if its possible.

I released a script version 1.0 and now I am about to release 1.2 version and i made some upgrade in database tables like change name field size or default value also added few new columns and table then export full db to .sql file(new db).

Is it possible from php to import new .sql file and add new tables and also change columns structure without deleting any data from table and add new columns in existing tables ?

I tried to import it but it shows this error : 'ALTER TABLE table1 ADD PRIMARY KEY (id); ': Multiple primary key defined

Example :

Old Database v1.0

Table 1

ID (primary key , AI)

First Name(size-50 ,default - none)

Last Name(size-50 ,default - none)

Email(size-50 ,default - none)

Password(size-50 ,default - none)


New Database v1.2

Table 1

ID (primary key , AI)

First Name(size-100 ,default - none)

Last Name(size-100 ,default - none)

Email(size-255 ,default - none)

Password(size-50 ,default - none)

Gender (size 10 , default - none)

Added Table 2

ID (primary key , AI)

coloum1 (size-100 ,default - none)

coloum2 (size-255 ,default - none)


Is it Possible to import new .sql over old database without loosing any data from php and also add data from new database?

I done my best to explain hope you understand.

EDIT : I use this code to import new .sql file and its not working: how to import .sql file in mysql database using php

Community
  • 1
  • 1
Sparsh
  • 301
  • 3
  • 9
  • Yes, absolutely possible. When you create your ALTER TABLE statements though, you should only include the changes - leave anything that already exists and doesn't need updating alone. – Ragdata Sep 19 '15 at 09:39

1 Answers1

0

you get that message because column id already exist and has KEY, if its PRIMARY KEY and AUTOINCREMENTED then it can not be duplicated, try this:

ALTER TABLE Table1 ADD COLUMN Gender varchar(10) NOT NULL DEFAULT 'none';
ALTER TABLE Table2 ADD COLUMN coloum1 varchar(100) NOT NULL DEFAULT 'none';
ALTER TABLE Table2 ADD COLUMN coloum2 varchar(255) NOT NULL DEFAULT 'none';

or just import the new columns

Red Acid
  • 217
  • 1
  • 3
  • 14