SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    319
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PDO using multiple values in one query

    Code PHP:
    $parents	= $db->prepare("
    			SELECT c.*, sc.is_visible, sc.id as sc_id 
    				FROM category c
    				JOIN site_category sc ON (c.category_id = sc.category_id AND sc.site_id = :site_id)
    				WHERE sc.parent_id = :parent_id  AND sc.site_id = :site_id  $categoryId  $isVisible
    			ORDER BY sc.position 
    		");
     
    		$parents->bindValue('site_id', 		$siteId);
    		$parents->bindValue('parent_id', 	$parentId);
    		$parents->execute();
    		$items = $parents->fetchAll(PDO::FETCH_OBJ);

    :site_id is used twice in the query. On Windows XP local using PHP 5.3.0 this query works. On a Mac Or Linux server this query spits out an error.

    My Question: Is this OS dependant or is it due to a setting in PHP / MYSQL.

    (note sure what forum this goes in, so I've put it in both PHP and MYSQL.

  2. #2
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    319
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PDO using multiple values in one query

    Code PHP:
    $parents	= $db->prepare("
    			SELECT c.*, sc.is_visible, sc.id as sc_id 
    				FROM category c
    				JOIN site_category sc ON (c.category_id = sc.category_id AND sc.site_id = :site_id)
    				WHERE sc.parent_id = :parent_id  AND sc.site_id = :site_id  $categoryId  $isVisible
    			ORDER BY sc.position 
    		");
     
    		$parents->bindValue('site_id', 		$siteId);
    		$parents->bindValue('parent_id', 	$parentId);
    		$parents->execute();
    		$items = $parents->fetchAll(PDO::FETCH_OBJ);

    :site_id is used twice in the query. On Windows XP local using PHP 5.3.0 this query works. On a Mac Or Linux server this query spits out an error.

    My Question: Is this OS dependant or is it due to a setting in PHP / MYSQL.

    (note sure what forum this goes in, so I've put it in both PHP and Mysql.

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,340
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    i'm guessing this isn't a mysql problem, even if it's a mysql error message (which you didn't specify)
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Evangelist
    Join Date
    Jun 2006
    Location
    Wigan, Lancashire. UK
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by azz0r_wugg View Post
    :site_id is used twice in the query. On Windows XP local using PHP 5.3.0 this query works. On a Mac Or Linux server this query spits out an error.

    My Question: Is this OS dependant or is it due to a setting in PHP / MYSQL.
    It shouldn't be platform or OS dependent, but it could be configuration dependent or even version dependent.

    Knowing exactly what error the query spits out could be very helpful in diagnosing the problem.
    ---
    Development Projects:
    PHPExcel
    PHPPowerPoint

  5. #5
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    This should get the err info, ftw.

    PHP Code:
    var_dump$items->errorInfo() ); 
    (Quite interested in this answer too)

  6. #6
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The manual sais you cannot use the same placeholder name multiple times.

  7. #7
    SitePoint Guru
    Join Date
    Oct 2008
    Location
    Melbourne
    Posts
    754
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Let's keep this in one thread, thanks.
    "I'm Commander Shepard, and this is
    my favourite post on the internet."

    We'll miss you, Dan Schulz.


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
  •