Content specified in the central part of the SQL replace Field

Source: Internet
Author: User
Tags mysql tutorial

Content specified in the central part of the SQL replace Field

Content specified in the central part of the SQL replace Field

Database creation tutorial

Create database cnnet;

Create a data table

Create table 'cnnet'. 'test '(
'Id' INT (4) not null AUTO_INCREMENT,
'Url' VARCHAR (50) NULL,
Primary key ('id ')
) ENGINE = MYISAM

Insert several data entries:

Insert into 'test' ('id', 'url') VALUES
(1, 'www. 1aa. cm '),
(2, 'www. 1aa. cm '),
(3, 'www. 1aa. cm '),
(4, 'www. 1aa. cm '),
(5, 'www. bKjia. c0m '),
(6, 'www. bKjia. c0m ');

Next let's take a look at the specified content in the middle of the SQL replace Field getting started tutorial.

Create a database connection
*/

$ Cn = mysql tutorial _ connect ('127. 0.0.1 ', 'root', 'root') or die ('database connection failed ');
$ SQL = "select * from test where url like '% 1aa. cm % '";
$ Result = mysql_db_query ('cnnet', $ SQL, $ cn );
While ($ rs = mysql_fetch_array ($ result ))
{
Echo $ rs ['url'], '<br/> ';
}

/*
Output result
Www.1aa. cm
Www.1aa. cm
Www.1aa. cm
Www.1aa. cm
The result is displayed. We will officially start the topic, replace the content, and we need to replace 1aa. cm with bKjia. c0m.
*/

$ SqlReplace = "update test set url = replace ('1aa. cm ', 'bkjia. c0m', url) WHERE url like' % 1aa. cm % '";
Mysql_db_query ('cnnet', $ sqlReplace, $ cn );
If (1)
{
$ SQL = "select * from test ";
$ Query = mysql_db_query ('cnnet', $ SQL, $ cn );
While ($ row = mysql_fetch_array ($ query ))
{
Echo $ rs ['url'], '<br/> ';
}
}
Else
{
Echo 'Check your SQL statement. Thank you ';
}

/*
Output result:

Www. bKjia. c0m
Www. bKjia. c0m
BKjia. c0m
BKjia. c0m
BKjia. c0m
BKjia. c0m

Original Site Article Reprinted with source www. bKjia. c0m
*/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.