나는 PHP에서 예전 방식으로 코드를 작성하고이 포럼을 통해 POO에 소개되었습니다. mysql에있는 스크립트를 PDO로 다시 작성합니다. 이 스크립트는 웹 사이트에 연결된 회원의 번호와 이름을 보여줍니다. ?연결된 사용자의 수와 이름 표시
<?php
session_start();
if(isset($_SESSION['nom'])){
include('class.connect.php');
include('class.user.php');
$db = new DBEngine();
//verify if the name is already in the table
$log = $db->con->prepare('SELECT COUNT(nom) AS name FROM members_connected WHERE nom=?');
$log->execute(array($_SESSION['nom']));
$count = $log->fetchColumn(0);
$time = time();
if ($count == 0)
{
// the user is not in the new table, i add him
$log = $db->con->prepare('INSERT INTO members_connected (nom,timestamp) VALUES(?,?)');
$log->execute(array($_SESSION['nom'],$time));
}
//name already in the table, update the timestamp
else
{
$log = $db->con->prepare('UPDATE members_connected SET timestamp=? WHERE nom=?');
$log->execute(array($_SESSION['name'],$time));
}
//5 min earlier's timestamp
$timestamp_5min = time() - (60 * 5);
$log = $db->con->prepare('DELETE FROM members_connected WHERE timestamp < ?');
$log-> execute(array($timestamp_5min));
$log = $db->con->prepare('SELECT nom FROM members_connected');
$log->execute();
$row = $log->fetch(PDO::FETCH_ASSOC);
echo $count ;
//show the list of connected
if($count > 0)
{
$i=0;
while($count = $log->fetch(PDO::FETCH_ASSOC));
{
$i++;
echo $count['nom'];
if($i<$row)
{
//space between names
echo ',';
}
}
}
}
>
`
어떤 생각하십시오 : 지금까지 그것은 단지 스크립트를 업데이트하는 수 있지만 아직
연결된 회원
의 이름의 목록이 표시?
POO? 글쎄, 그것은 나를 껄끄럽게 만들었다. ;-) – Strawberry
글쎄, 무엇이 오류입니까? – Eliel
@ 엘리엘 그것입니다. 치명적인 오류 : C : \ Program Files (x86) \ object \ context \ bladuo \ html \ connected_members.php에있는 객체 컨텍스트가 아닐 때 $ this를 사용하십시오. – Kuma