有一个类似的主题(How to access mysqli connection in another class on another page?)但它并没有完全回答我的问题,或者我错过了重点。我正在尝试构建一个类,它允许我通过从数据库中提取一组图像 url 和 div id 来快速构建幻灯片的骨架。这是我所管理的:
class make_slide
{
private $slide_mysqli;
public $get_slide;
public $single_slide;
public $get_imgurl1;
public $get_imgurl2;
public $get_imgurl3;
public $get_imgurl4;
public $get_imgurl5;
public $get_imgid1;
public $get_imgid2;
public $get_imgid3;
public $get_imgid4;
public $get_imgid5;
function __construct(){
$this->slide_mysqli = new mysqli('localhost','user', 'password','database') or die($this->mysqli->error);
}
function get_slides ($page)
{
if ($this->get_slide = $this->slide_mysqli->prepare('SELECT IMAGE_URL1, IMAGE_URL2, IMAGE_URL3, IMAGE_URL4, IMAGE_URL5, IMAGE_ID1, IMAGE_ID2, IMAGE_ID3, IMAGE_ID4, IMAGE_ID5 FROM Page WHERE ID=? AND IMAGE_URL1 != NULL'))
{
$this->get_slide->bind_param('s', $page);
$this->get_slide->bind_result($this->get_imgurl1, $this->get_imgurl2, $this->get_imgurl3, $this->get_imgurl4, $this->get_imgurl5, $this->get_imgid1, $this->get_imgid2, $this->get_imgid3, $this->get_imgid4, $this->get_imgid5);
$this->get_slide->execute();
$this->get_slide->store_result();
$this->get_slide->fetch();
$this->get_slide->free_result();
$this->get_slide->close();
}
//print the slideshow out here... for example
print '<br><img src="http://***.com/'.$this->get_imgurl1.'" alt="'.$this->get_imgid1.'" height="200"/></div>';
print '<br><img src="http://***.com/'.$this->get_imgurl1.'" alt="'.$this->get_imgid2.'" height="200"/></div>';
}
}
所以现在如果我运行以下命令,班级将为我完成所有工作:
$slide = new make_slide();
$slide->get_slides('home');
只是它在打印图像,但忽略了我从数据库中提取的内容。我检查了错误日志,我被告知
PHP 注意:使用未定义的常量 IMAGE_ID5 - 在 /var/www/ / .com/httpdocs/index.php 中的第 216 行假定为“IMAGE_ID5”,引用者:http://***.com/index.php
拜托,关于我做错了什么的任何线索?