PDO Question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mrfabulous
    New Member
    • Apr 2007
    • 1

    PDO Question

    I have the following code and it works fine. However since I have overlapping col names in my table, I want $row to include the tableName in the keys of the resulting assoc array. I don't want to explicitly list the cols of each table and I'd like to accomplish this in one query.:

    <[PHP]>
    $dbh = Database::getCo nnection($datab ase, 'r');
    $dbh->setAttribute(P DO::ATTR_ERRMOD E, PDO::ERRMODE_EX CEPTION);
    $sql = "SELECT cars.* , garages.* , parkingSpots.*
    FROM cars, garages, parkingSpots
    WHERE cars.id=:id AND
    cars.garage_id = garages.id AND
    cars.parkingSpo t_id = parkingSpots.id ";
    $stmt = $dbh->prepare($sql );
    $stmt->bindParam(':id ', $id);
    $stmt->execute();
    $rows = $stmt->fetchAll(PDO:: FETCH_ASSOC);

    # note the asso array keys include the table name
    # after this , I want $rows to look like this
    Array
    (
    [0] => Array
    (
    [cars.id] => 38011
    [cars.guid] =>
    [cars.postal_cod e] => 90404
    [cars.url] => www.14below.com
    [cars.phone] => 310.451.5040
    [cars.state] => CA
    [cars.country_co de] => US
    [cars.time_zone] => PST
    [cars.time_zone_ detailed] => America/Los_Angeles
    [cars.offset] => -8
    [cars.dst] => yes
    [cars.latitude] => 34.028496
    [cars.longitude] => -118.470151
    [cars.ticketing] =>
    [cars.station] =>
    [cars.ivn] => no
    [garages.venue_t ype] =>
    [garages.liveVen ue] => yes
    [garages.vip_exp erience] => no
    [garages.ln_owne d] => NOT_LN
    [garages.deleted] => no
    [garages.updated _at] => 2007-04-01 17:48:58
    [garages.lock_ve rsion] => 1
    [garages.venue_i d] => 11051
    [garages.name] => 14 Below
    [garages.city] => Santa Monica
    [parkingSpots.st ate_code] => CA
    [parkingSpots.ad dress1] => Corner Of 14th Street and Santa Monica Boulevard
    [parkingSpots.ad dress2] =>
    [parkingSpots.so undex] =>
    [parkingSpots.so undexSql] =>
    [parkingSpots.me taphone] =>
    [parkingSpots.lo cale] => en-us
    [parkingSpots.co untry] => us
    [parkingSpots.ar ea_code] => 310
    [parkingSpots.co unty_fips] => 06037
    [parkingSpots.co unty] => Los Angeles
    [parkingSpots.ti me_zone_name] => Pacific
    [parkingSpots.ma rket_code] => 1
    [parkingSpots.zi p_type] => S
    [parkingSpots.st ate_name] => California
    [parkingSpots.st ate_fips] => 06
    [parkingSpots.ms a_code] => 4480

    )

    )

    <[/PHP]>


    THanks
    mrfabulous
Working...