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
*/