lhbpping

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: :: 管理 ::

本文介绍怎样利用 PHP   SQLITE 制作简单的视频点播程序,这是一个简单的视频点播程序,设有过多的美观界面。下面介绍一下程序文件的功能:
1. init.php初始化数据库,及表文件;

 1 <?php
 2 $db = sqlite_open("db.sqlite");//创建并连接数据库
 3 $sql = "create table test (id INTEGER PRIMARY KEY,movie text,url text,content text ,time   datatime);";//创建表
 4 $result = sqlite_query($db,$sql);
 5 if ($result)
 6 {
 7 echo "数据初始化成功";
 8 echo "<a href='sql.php'>进入创建数据文件</a>";
 9 }
10 else
11 {
12 echo "数据初始化失败,请重试!";
13 }
14 ?>

2.form.php提供数据输入的表单;

 1 <form name="form1" method="post" action="add.php">
 2 <table width="48%" border="0" align="center" cellpadding="0" cellspacing="0">
 3 <tr> 
 4 <td width="36%" height="38"><div align="right">影片名称:</div></td>
 5 <td width="64%"> <input type="text" name="movie"> </td>
 6 </tr>
 7 <tr> 
 8 <td height="39"><div align="right">影片地址:</div></td>
 9 <td><input type="text" name="url"></td>
10 </tr>
11 <tr> 
12 <td height="33"><div align="right">影片简介:</div></td>
13 <td><textarea name="content"></textarea></td>
14 </tr>
15 <tr> 
16 <td height="53" colspan="2"><div align="center">
17 <input type="submit" name="Submit" value="确 定"> 
18 <input type="reset"   value="重 填">
19 </div></td>
20 </tr>
21 </table>
22 </form>

3.add.php添加表数据;

 1 <?php
 2 $movie = $_POST['movie'];
 3 $url = $_POST['url'];
 4 $content = $_POST['content'];
 5 $now = date("Y- m- d   H:i:s");
 6 if (trim($movie) =="" || trim($url) =="" || trim($content) =="")
 7 {
 8 echo "请填写完整数据再提交!";
 9 exit();
10 }
11 else
12 {
13 $db = sqlite_open("db.sqlite");
14 $sql = "insert into test (movie,url,content,time) values ( '$movie','$url','$content','$now')";
15 $result = sqlite_query($db,$sql);
16 if ($result)
17 {
18 echo "数据添加成功";
19 echo "点击<a href='sql.php'>该处</a>继续添加";
20 }
21 else
22 {
23 echo "数据添加失败,请检查后重试";
24 }
25 }
26 ?>

4.   index.php视频点播主界面;

 1 <?php
 2 $db = sqlite_open("db.sqlite");//连接数据库
 3 $sql = "select * from test ";
 4 $query = sqlite_query($db,$sql); //选出表中数据
 5 ?>
 6 <html> 
 7 <head> 
 8 <title>视频点播</title> 
 9 <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
10 </head> 
11  
12 <body> 
13 <table width="100%" border="1"> 
14 <tr> 
15 <?php
16 while ($res= sqlite_fetch_array($query))
17 {
18 // show the data
19 echo "<td>";
20 echo "<a href=red.php?id=" .$res['id'] .">" . $res['name'] ."</a>";
21 echo "</td>";
22 }
23  
24 ?>
25 <tr> 
26 </table> 
27 </body> 
28 </html>

5.show.php视频点播播放界面;

 1 <?php
 2 $id = $_GET['id'];//取得Id的值
 3  
 4 $db = sqlite_open("db.sqlite");//连接数据库
 5  
 6 $sql = "select * from test where id='$id'";
 7 $query = sqlite_query($db,$sql);
 8 $res = sqlite_fetch_array($query);//取出符合要求的数据
 9  
10 ?>
11 <HTML> 
12 <HEAD> 
13 <TITLE><?php echo $res['movie'] ;?></TITLE>
14 <META http-equiv=Content-Type content="text/html; charset=gb2312"> 
15 <META content="MSHTML 6.00.2800.1106" name=GENERATOR> 
16 </HEAD> 
17 <BODY bgcolor="#F4FFF4"> 
18 <table width="576" height="418" border="0" align="center" cellpadding="0" cellspacing="0">
19 <tr> 
20 <td height="62" colspan="3"><img src="vod1.jpg" width="590" height="62"></td> 
21 </tr> 
22 <tr> 
23 <td width="21%"><img src="vod2.jpg" width="130" height="290"></td> 
24 <td width="55%"> 
25 <object ID=RVOCX classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width=326 height=245>
26 <param name="src" value="rtsp://localhost:554/<?php echo $res['url'] ;?>">
27 <param name="controls" value="ImageWindow"> 
28 <param name="autostart" value="true"> 
29 <param name="console" value="_master"> 
30 <embed width="326" height="245" src="rtsp://localhost:554/<?phpecho $res['url'] ;?>" controls="ImageWindow"
31  console="_master" > 
32 </embed> 
33 </object> 
34  
35 <object ID=RVOCX classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width=326 height=40>
36 <param name="controls" value="ControlPanel"> 
37 <param name="console" value="_master"> 
38 <embed width="326" height="40" src="cabin_w_layout.rpm" 
39 controls="ControlPanel" console="_master" > 
40 </embed> 
41 </object></td> 
42 <td width="24%"><img src="vod4.jpg" width="135" height="289"></td> 
43 </tr> 
44 <tr> 
45 <td colspan="3"><img src="vod3.jpg" width="590" height="66"></td> 
46 </tr> 
47 </table> 
48 </body> 
49 </html>

补充一个

 1 <?php
 2 //打开sqlite数据库
 3 $db = @sqlite_open("abc.db");
 4 //异常处理
 5 if (!$db) die("Connection Sqlite failed.\n");
 6 //添加一个叫做foo的数据库
 7 @sqlite_query($db, "CREATE TABLE foo (bar varchar(10))");
 8 //插入一条记录
 9 @sqlite_query($db, "INSERT INTO foo VALUES ('fnord')");
10 //检索所有记录
11 $result = @sqlite_query($db, 'select bar from foo');
12 //打印获取的结果
13 print_r(sqlite_fetch_array($result)); 
14 ?>

 

posted on 2015-09-30 09:39  三渔  阅读(480)  评论(0)    收藏  举报