SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Sep 2007
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PDO - how to bind columns in separate tables to a same value

    Hi,

    I've found The PHP Anthology (PA) extremely useful for improving my knowledge after beginning with Kevin Yank's Introductory PHP/MySQL (KY) book.

    However one thing that is missing from The PHP Anthology (PA) is the following:

    KY regularly uses SELECT statements from multiple tables and a typical SQL SELECT statement might look like this:

    SELECT * FROM animals, animal_homes WHERE animals.homeId=animal_homes.id;

    Nowadays I'm using PDO Prepare and Execute as recommended in PA. However I don't know how to bind two columns to the same value as with the statement above where column animals.homeId is bound to column animal_homes.id.

    Would be very grateful for some help on this one, since I really want to persevere with Prep Ex.

    Thanks a million
    Michael

  2. #2
    SitePoint Addict
    Join Date
    Jul 2007
    Location
    San Jose, California
    Posts
    355
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Little confused by your question.

    Code MySQL:
    SELECT * FROM animals, animal_homes WHERE animals.homeId=animal_homes.id;

    Can be re written to:
    Code MySQL:
    SELECT * FROM animals a, animal_homes ah WHERE a.homeId=ah.id;

    Umm to bind the same value set it like this:

    Code PHP:
    $stmt->prepare("SELECT * FROM tbl1 WHERE col1 =?:var1 col2=?:var1")

    Now col1 and col2 have the same column.

  3. #3
    SitePoint Member
    Join Date
    Sep 2007
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many thanks,

    Problem sorted - I was overcomplicating things!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •