php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #57901 Add support for ATTR_FETCH_TABLE_NAMES
Submitted: 2007-11-08 10:35 UTC Modified: 2009-11-05 07:55 UTC
From: andrew dot minerd at sellingsource dot com Assigned:
Status: Closed Package: PDO_MYSQL (PECL)
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID: None
 [2007-11-08 10:35 UTC] andrew dot minerd at sellingsource dot com
Description:
------------
I've attached a patch that adds support for the fetch table name attribute to the PDO MySQL driver. This could be very helpful when building multiple data objects off subsets of the same query (i.e., one per table).

Reproduce code:
---------------
<?php

  $db = new PDO('mysql:host=localhost;dbname=test', 'root', '');
  $db->setAttribute(PDO::ATTR_FETCH_TABLE_NAMES, 1);

  $rows = $db->query('SELECT * FROM test LIMIT 1')->fetchAll(PDO::FETCH_ASSOC);
  var_dump($rows);

?>

Patch is available from: http://dothedrew.net/misc/pdo_mysql-fetch_tables.patch

Expected result:
----------------
array(1) {
  [0]=>
  array(2) {
    ["test.name"]=>
    string(6) "Andrew"
    ["test.id"]=>
    string(1) "1"
  }
}


Actual result:
--------------
array(1) {
  [0]=>
  array(2) {
    ["name"]=>
    string(6) "Andrew"
    ["id"]=>
    string(1) "1"
  }
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-05-22 16:57 UTC] ulf dot wendel at phpdoc dot de
Thanks for the code Andrew. The first PDO_MYSQLND beta version will have this feature.
 [2008-07-22 10:42 UTC] uwendel at mysql dot com
Please try again using PHP 5.3+ . You can download PHP 5.3+ from snaps.php.net.

Make sure that you try this with PHP 5.3+ and mysqlnd (--with-pdo-mysql=mysqlnd , default). It might not work when using the mysqlclient library (libmysql, --with-pdo-mysql=/path/to/mysql_config)
 [2009-11-05 07:55 UTC] ulf dot wendel at phpdoc dot de
Feature added in PHP 5.3.0
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 06:01:30 2024 UTC