<?php教程
$dbhost = 'localhost'; 資料庫教程伺服器
$dbuser = 'root'; 資料庫使用者名
$dbpw = 'qwaszx'; 資料庫密碼
$dbname = 'movie'; 資料庫名
$adminemail = www.jzread.com@jzread.com; 系統管理員 email
$database = 'mysql教程'; 不能修改此處
$tplrefresh = 1; 範本自動刷新開關 0=關閉, 1=打開
$pconnect = 0; 資料庫連接方式 0=connect, 1=pconnect
// ============================================================================
class db_class {
var $querynum = 0;
function dbstuff() { global $fp; $fp = fopen("./tempdata/dblog.txt", "w"); }
function connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect = 0) {
if($pconnect) {
if(!@mysql_pconnect($dbhost, $dbuser, $dbpw)) {
$this->halt('can not connect to mysql server');
}
} else {
if(!@mysql_connect($dbhost, $dbuser, $dbpw)) {
$this->halt('can not connect to mysql server');
}
}
mysql_query("set names 'gb2312'");
}
function select_db($dbname) {
return mysql_select_db($dbname);
}
function fetch_array($query, $result_type = mysql_assoc){
$query = mysql_fetch_array($query, $result_type);
return $query;
}
function query($sql, $silence = 0) {
//echo "|$sql|<br>"; //debug
//@fwrite($globals [fp], $sql." n"); debug
$query = mysql_query($sql);
//echo 'query:'.$query.' <br>';
if(!$query && !$silence)
{
& nbsp; $this->halt('mysql query error', $sql);
}
$this->querynum++;
return $query;
}
function unbuffered_query($sql, $silence = 0) {
$func_unbuffered_query = @function_exists(' mysql_unbuffered_query') ? 'mysql_unbuffered_query' : 'mysql_query';
$query = $func_unbuffered_query($sql);
if(!$query && !$silence) {
$this->halt('mysql query error', $sql);
}
$this->querynum++;
return $query;
}
function get_one($sql){
$sql=$sql;
if(function_ exists('mysql_unbuffered_query')){
$query = mysql_unbuffered_query($sql);
}else{
$query = mysql_query($sql);
}
$this->querynum++;
if (!$query) $this->halt('query error: ' . $sql);
$rs =& mysql_fetch_array($query, mysql_assoc);
mysql_free_result($query);
& nbsp; return $rs;
}
function affected_rows() {
return mysql_affected_rows();
}
function error() {
return mysql_error();
}
function errno() {
return mysql_errno();
}
function result($query, $row) {
$query = @mysql_result($query, $row);
return $query;
}
function num_rows($query) {
$query = mysql_num_rows($query);
return $query;
}
function num_fields($query) {
return mysql_num_fields($query);
}
function free_result($query) {
return mysql_free_result($query);
}
function insert_id() {
$id = mysql_insert_id();
return $id;
}
function fetch_row($query) {
$query = mysql_fetch_row($query);
return $query;
}
function close() {
return mysql_close();
}
function halt($message = '', $sql = '') {
echo $message;
}
}
***********************************************************/
========= 連接資料庫 =======================================================
$db = new db_class;
$db->connect($dbhost, $dbuser, $dbpw, $pconnect);
$db->select_db($dbname);
unset($dbhost, $dbuser, $dbpw, $dbname, $pconnect);
實例資料下載
<?
include './admin/connect.php';
@extract($db->get_one("select * from movieinfo where id='".$_get['id']."'"));
$db->query("update movieinfo set downnum=downnum+1 where id='".$_get['id']."'");
控制下載
$url2="./admin/";//存放電影的路徑
if($localaddress)
{
$newname=$localaddress;
$movieurl=$url2.$newname;
}
$type=basename($movieurl);
$type= substr(strrchr($type,'.'),0);
$filename=$title.$type;
$file=fopen($movieurl,'r');
ob_end_clean();
header('content-type: application/octet-stream');
header('accept-ranges: bytes');
header('accept-length:'.filesize($movieurl));
header("content-disposition: attachment; filename=".$filename);
echo fread($file,filesize($movieurl));
fclose($file);
exit;
?>