@@ -221,10 +221,42 @@ static char *dsn_from_uri(char *uri, char *buf, size_t buflen) /* {{{ */
221221}
222222/* }}} */ 
223223
224- /* {{{ */ 
225- PHP_METHOD (PDO , __construct )
224+ 
225+ #define  MAX_PDO_SUB_CLASSES  64
226+ static  unsigned int   number_of_pdo_driver_class_entries  =  0 ;
227+ static  pdo_driver_class_entry  * pdo_driver_class_entries [MAX_PDO_SUB_CLASSES ];
228+ 
229+ // It would be possible remove this and roll it into the standard driver class entries 
230+ // I chose not to do it at this time, as that would break existing PDO extensions 
231+ void  pdo_register_driver_specific_class (pdo_driver_class_entry  * driver_class_entry )
232+ {
233+ 	if  (number_of_pdo_driver_class_entries  >= MAX_PDO_SUB_CLASSES ) {
234+ 		// TODO - return false 
235+ 	}
236+ 
237+ 	pdo_driver_class_entries [number_of_pdo_driver_class_entries ] =  driver_class_entry ;
238+ 	number_of_pdo_driver_class_entries  +=  1 ;
239+ }
240+ 
241+ 
242+ static 
243+ void  create_specific_pdo_object (zval  * new_object , const  char  * driver_name )
244+ {
245+ 	for  (int  i = 0 ; i  <  number_of_pdo_driver_class_entries ; i  +=  1 ) {
246+ 		pdo_driver_class_entry  * driver_class_entry  =  pdo_driver_class_entries [i ];
247+ 		if  (strcmp (driver_class_entry -> driver_name , driver_name ) ==  0 ) {
248+ 			object_init_ex (new_object , driver_class_entry -> driver_ce );
249+ 			return ;
250+ 		}
251+ 	}
252+ 
253+ 	// No specific DB implementation found 
254+ 	object_init_ex (new_object , pdo_dbh_ce );
255+ }
256+ 
257+ static 
258+ void  internal_construct (INTERNAL_FUNCTION_PARAMETERS , zval  * object , zval  * new_zval_object )
226259{
227- 	zval  * object  =  ZEND_THIS ;
228260	pdo_dbh_t  * dbh  =  NULL ;
229261	bool  is_persistent  =  0 ;
230262	char  * data_source ;
@@ -291,7 +323,19 @@ PHP_METHOD(PDO, __construct)
291323		RETURN_THROWS ();
292324	}
293325
294- 	dbh  =  Z_PDO_DBH_P (object );
326+ 	if  (object  ==  NULL ) {
327+ 		ZEND_ASSERT ((driver -> driver_name  !=  NULL ) &&  "PDO driver name is null" );
328+ 		create_specific_pdo_object (new_zval_object , driver -> driver_name );
329+ 
330+ 		if  (new_zval_object  ==  NULL ) {
331+ 			zend_throw_exception_ex (php_pdo_get_exception (), 0 , "Failed to create specific PDO class" );
332+ 			RETURN_THROWS ();
333+ 		}
334+ 
335+ 		dbh  =  Z_PDO_DBH_P (new_zval_object );
336+ 	} else  {
337+ 		dbh  =  Z_PDO_DBH_P (object );
338+ 	}
295339
296340	/* is this supposed to be a persistent connection ? */ 
297341	if  (options ) {
@@ -432,8 +476,24 @@ PHP_METHOD(PDO, __construct)
432476		zend_throw_exception (pdo_exception_ce , "Constructor failed" , 0 );
433477	}
434478}
479+ 
480+ /* {{{ */ 
481+ PHP_METHOD (PDO , __construct )
482+ {
483+ 	zval  * object  =  ZEND_THIS ;
484+ 	internal_construct (INTERNAL_FUNCTION_PARAM_PASSTHRU , object , NULL );
485+ }
435486/* }}} */ 
436487
488+ 
489+ /* {{{ */ 
490+ PHP_METHOD (PDO , connect )
491+ {
492+ 	internal_construct (INTERNAL_FUNCTION_PARAM_PASSTHRU , NULL , return_value );
493+ }
494+ /* }}} */ 
495+ 
496+ 
437497static  zval  * pdo_stmt_instantiate (pdo_dbh_t  * dbh , zval  * object , zend_class_entry  * dbstmt_ce , zval  * ctor_args ) /* {{{ */ 
438498{
439499	if  (!Z_ISUNDEF_P (ctor_args )) {
@@ -1329,6 +1389,8 @@ static HashTable *dbh_get_gc(zend_object *object, zval **gc_data, int *gc_count)
13291389}
13301390
13311391static  zend_object_handlers  pdo_dbh_object_handlers ;
1392+ static  zend_object_handlers  pdosqlite_dbh_object_handlers ;
1393+ 
13321394static  void  pdo_dbh_free_storage (zend_object  * std );
13331395
13341396void  pdo_dbh_init (int  module_number )
@@ -1344,6 +1406,13 @@ void pdo_dbh_init(int module_number)
13441406	pdo_dbh_object_handlers .get_method  =  dbh_method_get ;
13451407	pdo_dbh_object_handlers .compare  =  zend_objects_not_comparable ;
13461408	pdo_dbh_object_handlers .get_gc  =  dbh_get_gc ;
1409+ 
1410+ 	memcpy (& pdosqlite_dbh_object_handlers , & std_object_handlers , sizeof (zend_object_handlers ));
1411+ 	pdosqlite_dbh_object_handlers .offset  =  XtOffsetOf (pdo_dbh_object_t , std );
1412+ 	pdosqlite_dbh_object_handlers .free_obj  =  pdo_dbh_free_storage ;
1413+ 	pdosqlite_dbh_object_handlers .get_method  =  dbh_method_get ;
1414+ 	pdosqlite_dbh_object_handlers .compare  =  zend_objects_not_comparable ;
1415+ 	pdosqlite_dbh_object_handlers .get_gc  =  dbh_get_gc ;
13471416}
13481417
13491418static  void  dbh_free (pdo_dbh_t  * dbh , bool  free_persistent )
0 commit comments