【发布时间】:2013-09-23 22:17:13
【问题描述】:
我正在尝试完成以下操作:
我有一个文件 conn.inc.php,其中包含名为 DatabaseConnection 的类:
pastebin(因为它有点长)
然后我有第二个包含称为bootstrap.inc.php:
<?php
global $dbcon;
$dbcon = new DatabaseConnection();
$dbcon->setHostname("localhost");
$dbcon->setUsername("root");
$dbcon->setPassword("password");
$dbcon->setDatabase("database");
?>
我还有第三个整体functions.inc.php,如果需要,它会被包括在内:
<?php include 'conn.inc.php'; ?>
<?php include 'bootstrap.inc.php'; ?>
<?php
function myFunction()
{
$db = $dbcon->getConnection();
$sql = "CALL ssp_MySP()";
$result = $db->query($sql) or trigger_error($db->error."[$sql]");
....
}
?>
现在,每次我调用 myFunction 时,我在打开连接时都会收到一个错误 -> $db = $dbcon->getConnection(); 说变量 $dbcon 未定义。
如何在位于functions.inc.php 的函数中使用$dbcon?
【问题讨论】: