Sensibilium
Programmer
Hi all,
Been a while since I've been here, good to see it's still alive and kicking. Anyway, onto my small issue.
I have produced an autoloading function for my PHP MVC framework, and have been happily proceeding without problem on my development server, but have hit a bit of a wall when testing on my production server.
Basically, when I try to instantiate a new PDO object, my autoload function is being called instead of the standard PDO class. This doesn't happen on my development server though, so I wondering whether this could be a configuration issue.
router.php
controllers/articles.php
libraries/drivers/PDOMysql_Driver.php
I hope someone has some ideas to move this forward, I've been banging my head against the keyboard for quite a while now.
If you need me to post more code (I think I have provided the relevant parts though), then let me know.
Thanks in advance.
Ahdkaw
Been a while since I've been here, good to see it's still alive and kicking. Anyway, onto my small issue.
I have produced an autoloading function for my PHP MVC framework, and have been happily proceeding without problem on my development server, but have hit a bit of a wall when testing on my production server.
Basically, when I try to instantiate a new PDO object, my autoload function is being called instead of the standard PDO class. This doesn't happen on my development server though, so I wondering whether this could be a configuration issue.
router.php
Code:
function autoLoader($className)
{
// parse out filename where class should be located
list($filename, $suffix) = explode('_', $className, 2);
switch (strtolower($suffix))
{
case 'model':
$folder = '/models/';
break;
case 'library':
$folder ='/libraries/';
break;
case 'driver':
$folder ='/libraries/drivers/';
break;
}
// build file name
$file = SERVER_ROOT . $folder .strtolower($filename) . DEFAULT_FILE_EXT;
// fetch file
if (file_exists($file))
{
// include the file
include_once($file);
}
else
{
// need to improve this error handling
die("File '$filename' containing class '$classname' not found.");
}
}
spl_autoload_register("autoloader");
...
controllers/articles.php
Code:
...
$connection = new PDOMysql_Driver;
// error occurs in below method
[b]$connection->connect();[/b]
...
libraries/drivers/PDOMysql_Driver.php
Code:
class PDOMysql_Driver extends Database_Library
{
private $connection; // Connection holds MySQLi resource
private $query; // Query to perform
private $statement; // Statement to perform
private $result; // Result holds data retrieved from server
private $prefix; // Prefix holds the table name prefix
/**
* Create new connection to database
*/
public function connect()
{
// connection parameters
$host = LOCALHOST;
$user = LOCALUSER;
$password = LOCALPASS;
$database = LOCALDB;
$port = NULL;
$socket = NULL;
// looks to my autoloader for some reason... ??
$this->connection = [b]new PDO[/b]
(
'mysql:host=localhost; dbname=' . $database, $user, $password
);
return TRUE;
}
...
}
I hope someone has some ideas to move this forward, I've been banging my head against the keyboard for quite a while now.
If you need me to post more code (I think I have provided the relevant parts though), then let me know.
Thanks in advance.
Ahdkaw