@@ -221,10 +221,42 @@ static char *dsn_from_uri(char *uri, char *buf, size_t buflen) /* {{{ */
221
221
}
222
222
/* }}} */
223
223
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 )
226
259
{
227
- zval * object = ZEND_THIS ;
228
260
pdo_dbh_t * dbh = NULL ;
229
261
bool is_persistent = 0 ;
230
262
char * data_source ;
@@ -291,7 +323,19 @@ PHP_METHOD(PDO, __construct)
291
323
RETURN_THROWS ();
292
324
}
293
325
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
+ }
295
339
296
340
/* is this supposed to be a persistent connection ? */
297
341
if (options ) {
@@ -432,8 +476,24 @@ PHP_METHOD(PDO, __construct)
432
476
zend_throw_exception (pdo_exception_ce , "Constructor failed" , 0 );
433
477
}
434
478
}
479
+
480
+ /* {{{ */
481
+ PHP_METHOD (PDO , __construct )
482
+ {
483
+ zval * object = ZEND_THIS ;
484
+ internal_construct (INTERNAL_FUNCTION_PARAM_PASSTHRU , object , NULL );
485
+ }
435
486
/* }}} */
436
487
488
+
489
+ /* {{{ */
490
+ PHP_METHOD (PDO , connect )
491
+ {
492
+ internal_construct (INTERNAL_FUNCTION_PARAM_PASSTHRU , NULL , return_value );
493
+ }
494
+ /* }}} */
495
+
496
+
437
497
static zval * pdo_stmt_instantiate (pdo_dbh_t * dbh , zval * object , zend_class_entry * dbstmt_ce , zval * ctor_args ) /* {{{ */
438
498
{
439
499
if (!Z_ISUNDEF_P (ctor_args )) {
@@ -1329,6 +1389,8 @@ static HashTable *dbh_get_gc(zend_object *object, zval **gc_data, int *gc_count)
1329
1389
}
1330
1390
1331
1391
static zend_object_handlers pdo_dbh_object_handlers ;
1392
+ static zend_object_handlers pdosqlite_dbh_object_handlers ;
1393
+
1332
1394
static void pdo_dbh_free_storage (zend_object * std );
1333
1395
1334
1396
void pdo_dbh_init (int module_number )
@@ -1344,6 +1406,13 @@ void pdo_dbh_init(int module_number)
1344
1406
pdo_dbh_object_handlers .get_method = dbh_method_get ;
1345
1407
pdo_dbh_object_handlers .compare = zend_objects_not_comparable ;
1346
1408
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 ;
1347
1416
}
1348
1417
1349
1418
static void dbh_free (pdo_dbh_t * dbh , bool free_persistent )
0 commit comments