Basically I am building a MVC app. In the Model, dbFunctions.php is this code:
<?php
require("config.php");
require("dbconnection.php");
class dbFunctions
{
// setting up the object to connect to the Database
function __construct()
{
$dbConnect = new dbConnection();
}
public function insertPortfolioAdminData($value='')
{
# code...
}
public function login($value='')
{
# code...
}
public function logout($value='')
{
# code...
}
public function dbStoreContactForm($value='')
{
# code...
}
// returns a query with a collection of database objects for the portfolio
public function fetchAllPortfolioItems()
{
$fetchAllPortfolioItemsReturnQry = mysql_query("SELECT description FROM PortfolioItems") or die ('Error: '.mysql_error ());
if($fetchAllPortfolioItemsReturnQry){
return $fetchAllPortfolioItemsReturnQry;
}
}
public function fetchSinglePortfolioItems($primaryKey='')
{
# code...
}
}
?>
dbConnection.php
<?php
require("config.php");
class dbConnection {
private $databaseConnection;
public function dbConnection(){
$databaseConnection = mysql_connect(dbHostName,dbUserName,dbPassword) or die(mysql_error());
mysql_select_db(dbDatabaseName) or die(mysql_error());
}
public function closeConnection(){
mysql_close($databaseConnection);
}
}
?>
The controller:
<?php
// Calling the class to do the work on database
require("./model/dbfunctions.php");
$dbMethods = new dbFunctions();
while($row = mysql_fetch_array($dbMethods->fetchAllPortfolioItems()))
{
$pageContent = $row["description"];
}
// calling the template
require("./views/page_12.php");
?>
Here’s the error:
Internal Server Error
The server encountered an internal
error or misconfiguration and was
unable to complete your request.Please contact the server
administrator,
webmaster@mvcportfolio.adambourg.com
and inform them of the time the error
occurred, and anything you might have
done that may have caused the error.More information about this error may
be available in the server error log.Additionally, a 404 Not Found error
was encountered while trying to use an
ErrorDocument to handle the request.
Basically I am trying to do all my DB work in the model then through the model pass it to the view to output it.
It’s maybe because you’re never actually connecting to the database before you query it.
Essentially, you’ve made a function with the same name as the class for
dbConnectioninstead of using the__constructmethod.