implemented peer PDO class binding
This commit is contained in:
parent
031542dd25
commit
6f7fbc98f8
2 changed files with 29 additions and 4 deletions
|
|
@ -2,6 +2,7 @@
|
|||
require("../php/config.php");
|
||||
require("network.php");
|
||||
require("bencoder.php");
|
||||
require("peer.php");
|
||||
$DB_NAME = "torrent";
|
||||
$ANN_MIN_INTERVAL = 15;
|
||||
$ANN_INTERVAL = 60;
|
||||
|
|
@ -74,10 +75,8 @@ $conn = new PDO("mysql:host=$DB_HOST;dbname=$DB_NAME", $DB_USER, $DB_PASS);
|
|||
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
$stmt = $conn->prepare("REPLACE INTO `peers` (info_hash, ip, port, update_time) VALUES (:info_hash, :ip, :port, :update_time)");
|
||||
$stmt->bindValue(":info_hash", $hash, PDO::PARAM_STR);
|
||||
$stmt->bindValue(":ip", is_loopback($ip) ? $externalIp : $ip, PDO::PARAM_STR);
|
||||
$stmt->bindValue(":port", $port, PDO::PARAM_INT);
|
||||
$stmt->bindValue(":update_time", $now, PDO::PARAM_STR);
|
||||
$peer = new Peer($hash, is_loopback($ip) ? $externalIp : $ip, $port);
|
||||
$peer->bind($stmt);
|
||||
$stmt->execute();
|
||||
|
||||
$peers = '';
|
||||
|
|
|
|||
26
peer.php
Normal file
26
peer.php
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
class Peer {
|
||||
protected $info_hash;
|
||||
protected $ip;
|
||||
protected $port;
|
||||
protected $update_time;
|
||||
|
||||
public function __construct($hash, $ip, $port) {
|
||||
$this->info_hash = $hash;
|
||||
$this->ip = $ip;
|
||||
$this->port = $port;
|
||||
|
||||
$date = new DateTime("now");
|
||||
$this->update_time = $date->format('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
public function bind($stmt) {
|
||||
$stmt->bindValue(":info_hash", $this->info_hash, PDO::PARAM_STR);
|
||||
$stmt->bindValue(":ip", $this->ip, PDO::PARAM_STR);
|
||||
$stmt->bindValue(":port", $this->port, PDO::PARAM_INT);
|
||||
$stmt->bindValue(":update_time", $this->update_time, PDO::PARAM_STR);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Loading…
Add table
Reference in a new issue