Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/243.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php mysql\u fetch\u具有特定类的对象_Php_Mysql_Database_Class - Fatal编程技术网

Php mysql\u fetch\u具有特定类的对象

Php mysql\u fetch\u具有特定类的对象,php,mysql,database,class,Php,Mysql,Database,Class,我开发了一个面向对象的留言簿,我的类GuestBookEntry: class GuestBookEntry { protected $id; protected $entryDate; protected $authorName; protected $authorMail; protected $entryText; // getters, setters and specific functions are omitted } 我还有一个与列同名的mysql表 嗯,当我获取留言簿

我开发了一个面向对象的留言簿,我的类
GuestBookEntry

class GuestBookEntry {
protected $id;
protected $entryDate;
protected $authorName;
protected $authorMail;  
protected $entryText; 

// getters, setters and specific functions are omitted
}
我还有一个与列同名的
mysql

嗯,当我获取留言簿条目时,它似乎可以工作,但它只显示由getter返回的
ID
Date
。其他内容将不会返回到模板

代码如下所示:

public function showEntries() { 
    $query = mysql_query('SELECT * FROM dng_entries ORDER BY id DESC');     
    while($entry = @mysql_fetch_object($query, 'GuestBookEntry')) {
        if(empty($entry)) {
        echo '<font color="white">Keine Eintr&auml;ge vorhanden...</font>';
        } else {    
        var_dump($entry);
        echo '<table class="table table-bordered entryfield" align="right">
                <thead>
                    <tr>
                        <td rowspan="2">'.$entry->getId().'</td>
                        <td width="20%">Datum:</td>
                        <td>Name:</td>
                        <td>Email:</td>
                    </tr>
                    <tr>
                        <td>'.$entry->getEntryDate().'</td>
                        <td>'.$entry->getAuthorName().'</td>
                        <td><a href="mailto:'.$entry->getAuthorMail().'">'.$entry->getAuthorMail().'</a></td>
                </thead>
                <tbody>
                    <tr>
                    <td width="10%" valign="middle">Eintrag:</td>
                    <th colspan="3" valign="top" height="100px">'.$entry->getEntryText().'</td>
                    </tr>
                </tbody>
            </table>';
        }
    }
}
更新:这是客房部的其他课程:

public function __construct($authorName, $authorMail, $entryText) {
       $this->authorName    = $authorName;
       $this->authorMail    = $authorMail;
       $this->entryDate     = time();
       $this->entryText     = $entryText;
    }

    public function getId() {
       return $this->id;
    }
    public function getAuthorName() {
       return (String) $this->authorName;
    }
    public function getAuthorMail() {
       return (String) $this->authorMail;
    }
    public function getEntryDate() {
       return date('d.n.Y', $this->entryDate);
    }
    public function getEntryText() {
       return $this->entryText;
    }

    public function setAuthorName($authorName) {
       $this->authorName=$authorName;
    }   
    public function setAuthorMail($authorMail) {
       $this->authorMail=$authorMail;
    }
    public function setEntryDate($entryDate) {
       $this->entryDate=$entryDate;
    }
    public function setEntryText($entryText) {
       $this->entryText=$entryText;
    }

你的问题是区分大小写。MySQL列名不处理camel大小写,但PHP可以看到基于大小写的属性之间的区别,例如$entryDate和$entryDate。如果需要视觉分隔,请使用小写加下划线。
id
之所以有效,是因为它都是小写的

我认为,如果您简单地将所有应该映射到表列的属性名小写,那么一切都将正常工作


顺便说一句。。。列名的驼峰大小写问题可能因运行sql server的操作系统而异。

您的问题是区分大小写。MySQL列名不处理camel大小写,但PHP可以看到基于大小写的属性之间的区别,例如$entryDate和$entryDate。如果需要视觉分隔,请使用小写加下划线。
id
之所以有效,是因为它都是小写的

我认为,如果您简单地将所有应该映射到表列的属性名小写,那么一切都将正常工作


顺便说一句。。。根据运行sql server的操作系统的不同,列名的大小写问题可能会有所不同。

请停止使用古老的mysql_*函数编写新代码。它们不再得到维护,社区已开始恢复。相反,您应该学习准备好的语句,并使用或。如果你想学习。并且不要使用
@
运算符。您的
guestBookEntry
class getter/setter中可能有一些有趣的事情,显示它们的代码。您包含的
var\u dump()
输出显示您的一些属性,例如
authorName
NULL
。你检查过查询返回的数据了吗?到底是什么
mysql\u fetch\u object
。不要使用它。请添加您的db create语句。请停止使用古老的mysql_*函数编写新代码。它们不再得到维护,社区已开始恢复。相反,您应该学习准备好的语句,并使用或。如果你想学习。并且不要使用
@
运算符。您的
guestBookEntry
class getter/setter中可能有一些有趣的事情,显示它们的代码。您包含的
var\u dump()
输出显示您的一些属性,例如
authorName
NULL
。你检查过查询返回的数据了吗?到底是什么
mysql\u fetch\u object
。不要使用它。请添加您的db create语句。
public function __construct($authorName, $authorMail, $entryText) {
       $this->authorName    = $authorName;
       $this->authorMail    = $authorMail;
       $this->entryDate     = time();
       $this->entryText     = $entryText;
    }

    public function getId() {
       return $this->id;
    }
    public function getAuthorName() {
       return (String) $this->authorName;
    }
    public function getAuthorMail() {
       return (String) $this->authorMail;
    }
    public function getEntryDate() {
       return date('d.n.Y', $this->entryDate);
    }
    public function getEntryText() {
       return $this->entryText;
    }

    public function setAuthorName($authorName) {
       $this->authorName=$authorName;
    }   
    public function setAuthorMail($authorMail) {
       $this->authorMail=$authorMail;
    }
    public function setEntryDate($entryDate) {
       $this->entryDate=$entryDate;
    }
    public function setEntryText($entryText) {
       $this->entryText=$entryText;
    }