Jump to content

Change The Content Of A Mysql Database

Recommended Posts

HelloI have create a mysql database and i have store there some information.The problem is that i want to change some of these informations which is the same in all of my database tables.What did i mean?I guess that you haven't understand what is my problem :) so i am writing the following example.Let's say that the following text is into one of my database tables

Today is a beautiful day

And this one into one other

Dog is an animal

How can i change the "is" with "is not" without changing the other words?

Link to post
Share on other sites

You'd best make a function in php to perform this for you, with SQL you can select all the entries with 'is' by doing:SELECT * FROM table WHERE info LIKE '% is %'From there do a php to get the index of the string ' is ' from within the information and change it to is not and echo all this to for a new sql ready for an update

Link to post
Share on other sites
update table set col=concat(														substr(col,1,instr(col,' is ')-1),														' is not ',														 substr(col,instr(col,' is ')+4, length(col)-(instr(col,' is ')+3))														)where col like '% is %'and col not like '% is not %'   (very important, otherwise you will get things  like "is not not" whether you do PHP o SQL)

I didn't tested, & since it's manipulation query test it on a copy a part first, or better, try the same expression with a select statment.there are good reasons, like performance, safety, control, code and work saving, code reuse for different services, system maintenance strategy, storing procedures and so on and so forth to perform such an action on the DBMS side, that's my point of view!!!Or may be, he just wants to hake a site injecting SQL code (kidding)By the way, why don't you want dogs to be animals?stefano de boni

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...