Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PDO class not instantiated, autoloader used instead. 1

Status
Not open for further replies.

Sensibilium

Programmer
Apr 6, 2000
310
0
0
GB
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
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
 
the autoload mechanism will only be called if the class is not available in the current scope. this is suggestive that the PDO extension has not been loaded.

can you post the results of the phpinfo() call? that will give some definitive information on whether PDO is loaded together with its drivers.
 
This is what I thought, but my host denies it. Here's the relevent parts from my phpinfo() call:

Code:
Configure Command 	'./configure' '--enable-bcmath' '--enable-calendar' '--enable-ftp' '--enable-gd-native-ttf' '--enable-libxml' '--enable-magic-quotes' '--enable-mbstring' '--enable-pdo=shared' '--enable-soap' '--enable-sockets' '--enable-wddx' '--enable-zip' '--prefix=/usr' '--with-curl=/opt/curlssl/' '--with-freetype-dir=/usr' '--with-gd' '--with-gettext' '--with-imap=/opt/php_with_imap_client/' '--with-imap-ssl=/usr' '--with-jpeg-dir=/usr' '--with-kerberos' '--with-libexpat-dir=/usr' '--with-libxml-dir=/opt/xml2' '--with-libxml-dir=/opt/xml2/' '--with-mcrypt=/opt/libmcrypt/' '--with-mysql=/usr' '--with-mysql-sock=/var/lib/mysql/mysql.sock' '--with-mysqli=/usr/bin/mysql_config' '--with-openssl=/usr' '--with-openssl-dir=/usr' '--with-pdo-mysql=shared' '--with-pdo-sqlite=shared' '--with-png-dir=/usr' '--with-sqlite=shared' '--with-ttf' '--with-xmlrpc' '--with-xpm-dir=/usr/X11R6' '--with-xsl=/opt/xslt/' '--with-zlib' '--with-zlib-dir=/usr'
Server API 	CGI
Virtual Directory Support 	disabled
Configuration File (php.ini) Path 	/usr/lib
Scan this dir for additional .ini files 	(none)
additional .ini files parsed 	(none)
PHP API 	20041225
PHP Extension 	20060613
Zend Extension 	220060519
Debug Build 	no
Thread Safety 	disabled
Zend Memory Manager 	enabled
IPv6 Support 	enabled
Registered PHP Streams 	https, ftps, compress.zlib, php, file, data, http, ftp, zip
Registered Stream Socket Transports 	tcp, udp, unix, udg, ssl, sslv3, sslv2, tls
Registered Stream Filters 	zlib.*, convert.iconv.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed
PDO is not mentioned anywhere else in the info, only in the Configure Command...

Ahdkaw
 
if there is not a separate section for PDO and its drivers, the PDO extension is not loaded.

because PDO has been installed as shared modules you must include the relevant extension lines in your php.ini

Code:
extension=pdo.so
some PDO drivers also need to be loaded via php.ini
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top