The use of text database is generally for small applications, this does not need to install the database, we can directly manipulate the text file can be, but how to operate as well as the MySQL database, let me introduce a text database to MySQL database instance.
The code is as follows |
Copy Code |
Require_once ' config.php '; $action = Empty ($_get[' action ')? ": $_get[' action ']; $id = Isset ($_get[' id ')? $_get[' id ']: 0; if (empty ($action)) {//List $result = "SELECT * from posts ORDER by PID DESC"; $items = 3; $page = isset ($_get[' page ')? Intval ($_get[' page '): 1; $page = ($page = = "&& $page < 0)? 1: $page; $total = Mysql_num_rows (mysql_query ($result));//Data Entry Total $pageall = Ceil ($total/$items); $offset = ($page-1) * $ITEMS;//Data start position $result. = "Limit {$offset},{$items}";//Display per page $results = mysql_query ($result); $prev = $page-1; $next = $page + 1; $goPrev = "Previous page"; $goNext = "Next page"; if ($page = = $pageall) {$goNext = NULL;} $pagestate = "; if ($page = = 1 && $pageall > 1) { $pagestate. = $goNext; } elseif ($pageall > $page | | $page >1) { $pagestate. = $goNext. ' | '. $goPrev; } elseif ($page >1) { $pagestate. = $goPrev; } else { $pagestate. = ' Just one Page '; } $pagelinks = "; for ($i = 1; $i <= $pageall; $i + +) { $pagelinks. = ($i! = $page)? "$i": $i; $pagelinks. = ($i < $pageall)? '-': null; } End Paging $data = Array (); List articles while ($row = Mysql_fetch_array ($results)) {//mysql_fetch_array; Removes a row from the query result as an array; $data [] = $row;// } List categories $recat = mysql_query ("Select * from category ORDER by CID DESC"); $cdata = Array (); while ($catlist = Mysql_fetch_array ($recat)) { $cdata [$catlist [' cid ']] = $catlist; } Include template (' Index '); } elseif ($action = = ' Post ') {//Post $title = $_post[' title ']; $date = Date ("y-m-d h:i:s"); $content = $_post[' content ']; $cid = $_post[' cat ']; if ($title = = ' | | $content = = ' | | $cid = = ') { echo "Missing required fields nnnn return"; } else { $insertPost = "INSERT into posts (title,time,post,cid) VALUES (' $title ', ' $date ', ' $content ', ' $cid ')"; if (!mysql_query ($insertPost, $sql)) { Die (' ERROR: '. mysql_error ()); } Header (' location:index.php '); } } elseif ($action = = ' View ') {//view $view = mysql_query ("Select * from posts WHERE pid= ' $id '"); while ($row = Mysql_fetch_array ($view)) { $title = $row [' title ']; $time = $row [' Time ']; $post = $row [' Post ']; } if ($_server[' request_method ') = = ' POST ') {//comment $name = isset ($_post[' name ')? $_post[' name ']: 0; $review = Isset ($_post[' review ')? $_post[' review ': 0; if ($name = = ' && $review = = ') {echo "Missing required"; exit;} $insertRview = "INSERT into review (Pid,name,review) VALUES (' $id ', ' $name ', ' $review ')"; if (!mysql_query ($insertRview, $sql)) { Die (' ERROR: '. mysql_error ()); } Header ("Location: action=view&id= $id"); } $rert = mysql_query ("SELECT * from Review WHERE pid= ' $id ' ORDER by RID ASC"); $data = Array (); while ($relist = Mysql_fetch_array ($rert)) { $data [] = $relist; } Include template (' View '); } elseif ($action = = ' del ') {//delete mysql_query ("DELETE from posts WHERE pid= ' $id '"); Header ("location:index.php"); } elseif ($action = = ' edit ') {//Edit if ($_server[' request_method '] = = ' POST ') { $title = $_post[' title ']; $content = $_post[' content ']; $date = Date ("y-m-d h:i:s"); if ($title = = "or $content = =") {echo "Missing required nnnn return"; exit;} mysql_query ("UPDATE posts SET title= ' $title ', time= ' $date ', post= ' $content ' WHERE pid= ' $id '"); Header ("location:index.php"); } else { $row = mysql_query ("Select * from posts WHERE pid= ' $id '"); $row = Mysql_fetch_array ($row); Include template (' edit '); } } elseif ($action = = ' Newcat ') {//new category $cat = isset ($_post[' category ')? $_post[' category ']: 0; if ($_server[' request_method '] = = ' POST ') { if ($cat = = ") {echo" Missing required fields nnnn return "; exit;} $insertCat = "INSERT into category VALUES (' $cat ')"; if (!mysql_query ($insertCat, $sql)) { Die (' ERROR: '. mysql_error ()); } Header ("location:index.php"); } Include template (' Jioncat '); } elseif ($action = = ' VCAT ') { $cid = $_get[' cid ']; $revcats = "SELECT * from posts WHERE cid= ' $cid ' ORDER by CID DESC"; $items = 1; $page = isset ($_get[' page ')? Intval ($_get[' page '): 1; $page = ($page = = "&& $page < 0)? 1: $page; $total = Mysql_num_rows (mysql_query ($revcats));//Data Entry Total $pageall = Ceil ($total/$items); $offset = ($page-1) * $ITEMS;//Data start position $revcats. = "Limit {$offset},{$items}";//Display per page $revcat = mysql_query ($revcats); $prev = $page-1; $next = $page + 1; $goPrev = "Previous page"; $goNext = "Next page"; if ($page = = $pageall) {$goNext = NULL;} $pagestate = "; if ($page = = 1 && $pageall > 1) { $pagestate. = $goNext; } elseif ($pageall > $page | | $page >1) { $pagestate. = $goNext. ' | '. $goPrev; } elseif ($page >1) { $pagestate. = $goPrev; } else { $pagestate. = ' Just one Page '; } $pagelinks = "; for ($i = 1; $i <= $pageall; $i + +) { $pagelinks. = ($i! = $page)? "$i": $i; $pagelinks. = ($i < $pageall)? '-': null; } $data = Array (); while ($vclist = Mysql_fetch_array ($revcat)) { $data [] = $vclist; } Include template (' cplist '); } Mysql_close ($sql); |
An off-topic, an instance of access converted to a MySQL database
Click to download: Http://file.bKjia.c0m/download/2013/05/14/db2mysql.zip
http://www.bkjia.com/PHPjc/630714.html www.bkjia.com true http://www.bkjia.com/PHPjc/630714.html techarticle The use of text database is generally for small applications, this does not need to install the database, we can directly manipulate the text file can be, but how to operate than M ...