3

I want to Alter my database table (Add Columns) using query. I have done this :

This is my first query (Run Successfully) :

$database->pdoQuery("ALTER TABLE tbl_mytable ADD column1 varchar(100)");

This is my second query (gives an error) :

$database->pdoQuery("ALTER TABLE tbl_mytable ADD column2 text");

I have got this error message:

Executed Query -> ALTER TABLE tbl_mytable ADD column2 text
ERROR:"SQLSTATE[HY000]: General error: 315"

Can any one solve my problem? Any help would get appreciated.

2 Answers 2

1

$db->query("ALTER TABLE tbl_mytable ADD column2 text NOT NULL AFTER column1");

Sign up to request clarification or add additional context in comments.

Comments

1

You didn't say which versions you're using.

Your query is not wrong, but it could be your (older) MySQL version. Add backticks to your query:

$database->pdoQuery("ALTER TABLE `tbl_mytable` ADD `column2` text");

1 Comment

Tried but same result. :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.