Create a database tutorial
CREATE database cnnet;
Creating data Tables
CREATE TABLE ' cnnet '. ' Test ' (
' ID ' INT (4) Not NULL auto_increment,
' URL ' VARCHAR NULL,
PRIMARY KEY (' id ')
) ENGINE = MYISAM
Insert a few data:
INSERT into ' test ' (' id ', ' url ') VALUES
(1, ' www.1aa.cm '),
(2, ' www.1aa.cm '),
(3, ' www.1aa.cm '),
(4, ' www.1aa.cm '),
(5, ' www.111cn.net '),
(6, ' www.111cn.net ');
Now let's take a look at the introductory tutorial.
Creating 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 results
www.1aa.cm
www.1aa.cm
www.1aa.cm
www.1aa.cm
The good result comes out, we formally carry on the topic, replace replaces the content, we request to replace the 1aa.cm all to 111cn.net
*/
$sqlReplace = "Update test set URL = replace (' 1aa.cm ', ' 111cn.net ', 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 results:
www.111cn.net
Www.111cn.net
111cn.net
111cn.net
111cn.net
111cn.net
Note the original article reproduced in this site and indicate the source www.111cn.net
*/