- 001
- 002
- 003
- 004
- 005
- 006
- 007
- 008
- 009
- 010
- 011
- 012
- 013
- 014
- 015
- 016
- 017
- 018
- 019
- 020
- 021
- 022
- 023
- 024
- 025
- 026
- 027
- 028
- 029
- 030
- 031
- 032
- 033
- 034
- 035
- 036
- 037
- 038
- 039
- 040
- 041
- 042
- 043
- 044
- 045
- 046
- 047
- 048
- 049
- 050
- 051
- 052
- 053
- 054
- 055
- 056
- 057
- 058
- 059
- 060
- 061
- 062
- 063
- 064
- 065
- 066
- 067
- 068
- 069
- 070
- 071
- 072
- 073
- 074
- 075
- 076
- 077
- 078
- 079
- 080
- 081
- 082
- 083
- 084
- 085
- 086
- 087
- 088
- 089
- 090
- 091
- 092
- 093
- 094
- 095
- 096
- 097
- 098
- 099
- 100
<?php
class db {
var $MySQL_time_taken = 0;
function __construct ($mysql_host,$mysql_user,$mysql_pass,$mysql_db,$mysql_charset="cp1251") {
// global $mysql_host,$mysql_user,$mysql_pass,$mysql_db;
if(!($this->link = @mysqli_connect($mysql_host,$mysql_user,$mysql_pass)))
{
echo "<font color=\"red\">Error:</font> connect to host: $mysql_host";
//exit();
}
if(!mysqli_select_db($this->link,$mysql_db))
{
echo "<font color=\"red\">Error:</font> select database $mysql_db";
exit();
}
mysqli_query($this->link,"SET NAMES $mysql_charset");
return $this->link;
}
function sql_query ($query,$debug=false) {
$time_befor = $this->get_real_time();
$result = mysqli_query($this->link, $query);
if (!$result)
{
$this->error_msg = mysqli_error($result);
return print($this->error_msg);
}
$this->MySQL_time_taken += $this->get_real_time() - $time_before;
//print("<font color=\"blue\">" . $time . "</font><br>");
return $result;
}
function sql_fetch_assoc ($query) {
$res=sql_query($query);
while ($rows = mysqli_fetch_assoc($res))
{
$row[]=$rows;
}
mysqli_free_result($res);
return $row;
}
function sql_fetch_array ($query,$numarr=MYSQLI_BOTH) {
$res = $this->sql_query($query);
while ($row = mysqli_fetch_array($res,$numarr))
{
$array[] = $row;
}
mysqli_free_result($res);
return $array;
}
function get_id_passkey ($passkey) {
$query = "SELECT id FROM users WHERE passkey='" . $passkey . "'";
$res=$this->sql_query($query);
$row = mysqli_fetch_array($res);
mysqli_free_result($res);
return $row;
}
function get_real_time()
{
list($seconds, $microSeconds) = explode(' ', microtime());
return ((float)$seconds + (float)$microSeconds);
}
function torrent_search ($string,$owner="",$sort="added",$cat="all",$checked="2")
{
$limit = 10;
$stmt = mysqli_prepare($this->link, "SELECT id,name,owner,added,cheched FROM torrents WHERE name '%?%' AND checked='?' AND owner='?'SORT BY ? LIMIT ?");
var_dump($stmt);
//mysqli_bind_param('sissi', $string,$checked,$owner,$sort,$limit);
mysqli_bind_param(mysqli_stmt_init($this->link),'sissi', $string,$checked,$owner,$sort,$limit);
mysqli_stmt_execute($stmt) or die("Ошибка: Неудачный запрос");
$stmt = mysqli_stmt_bind_result($id, $name, $owner, $added, $checked);
while ($stmt->fetch()) {
echo "|" . $id . " || " . $name . " || " . $owner . " || " . $added . " || " . $checked . "|<br>";
}
mysqli_stmt_close($stmt);
}
function catlist()
{
$query = "SELECT id, name FROM categories ORDER BY sort ASC";
$ret = $this->sql_fetch_array($query);
$cats_list = "";
foreach ($ret as $cats_list_array)
{
$cats_list .= "<option name=\"" . $cats_list_array["id"] . "\">" . $cats_list_array["name"] . "</option>";
}
return $cats_list;
guest 10.07.2009 15:57 # +2