2014-09-27 60 views
0

我想製作一個系統,需要用戶默認時區,然後將其轉換爲服務器時區。這是用於任何用戶可以在我的網站上查看的IP日誌。我完全難倒...調用未定義的方法PDOStatement :: fetch_array()

<?php 
    $SQLGetIP = $odb -> prepare("SELECT * FROM `loginip` WHERE `username` = :username ORDER BY `loginip`.`date` DESC"); 
    $SQLGetIP -> execute(array(':username' => $_SESSION['username'])); 
     $getInfo = $SQLGetIP->fetch_array(); 

    $query = $odb -> prepare("SELECT * FROM `users` WHERE `id` = :id"); 
    $query -> execute(array(':id' => $_SESSION['id'])); 
     $data = $query->fetch_array(); 


    $dt1 = $getInfo['date']; 
    $tz = $data['timezone']; 
    $dt = new DateTime("@".$dt1.""); 
    $dt -> setTimeZone(new DateTimeZone($tz)); 

    $IP = $getInfo['logged']; 
    $Date = $dt->format('F d, Y - h:i:s A'); 

     echo '<tr><td>'.$IP.'</td><td>'.$Date.'</td></tr>'; 

    ?> 
+0

你有兩個對fetch_array()的調用。哪一個是造成它的? – chanchal118 2014-09-27 06:47:48

+0

爲什麼會發生該錯誤?它應該在用戶時區中顯示日期,但它不會。我的PHP錯誤日誌顯示[27-Sep-2014 06:31:03 UTC] PHP致命錯誤:調用未定義的方法PDOStatement :: fetch_array()在/home/public_html/iplogs.php在線84 – 2014-09-27 06:48:37

+0

這條線是84這裏? – chanchal118 2014-09-27 06:50:48

回答

0

不應該說,它是:

$resultset = $query -> execute(array(':id' => $_SESSION['id'])); 
$data = $resultset->fetch_array(); 
+0

不需要任何賦值就可以調用execute。 – chanchal118 2014-09-27 06:50:23

1

$result = $sth->fetch(fetch_style);

fetch_style可以是:

PDO::FETCH_ASSOC 

PDO::FETCH_BOTH (default) 

PDO::FETCH_BOUND 

PDO::FETCH_CLASS 

PDO::FETCH_INTO 

PDO::FETCH_LAZY 

PDO::FETCH_NAMED: 

PDO::FETCH_NUM 

PDO::FETCH_OB 

裁判:http://php.net/manual/en/pdostatement.fetch.php

相關問題