PHP - odbc_connect - Inner Join Error

Posted on 2008-11-13
Last Modified: 2013-12-13
I have a PHP file created out of Dreamweaver and when I run it with the following query it works fine.

$query = "select [901_UNID] as UNID, [901_Abbreviation] as Abbreviation, [901_Name] as Name from [901-GeoState]";

When I put the following query in it fails with a 500 error.

$query = "
[901-GeoState].[901_Abbreviation] AS Abbreviation, [901-GeoState].[901_Name] AS Name, [900-GeoCountry].[900_Country] AS Country
[901-GeoState] ON [900-GeoCountry].[900_UNID] = [901-GeoState].[901_CountryID]"

Not sure why this is happening. The inner join query works in the SQL Server Query Editor.

Thanks in advance

//connect to a DSN "myDSN" 

$conn = odbc_connect('DATABASE','USER','PASSWORD'); 

if ($conn) 


	//the SQL statement that will query the database 

	$query = "


	[901-GeoState].[901_Abbreviation] AS Abbreviation, [901-GeoState].[901_Name] AS Name, [900-GeoCountry].[900_Country] AS Country 






	[901-GeoState] ON [900-GeoCountry].[900_UNID] = [901-GeoState].[901_CountryID]"


	//perform the query 

	$result=odbc_exec($conn, $query); 

	echo ("<?xml version=\"1.0\"?>\n\n");

	echo ("<result>\n");

	//fetch tha data from the database 



    	echo ("<tablerow>\n");



      		$tag = odbc_field_name ($result, $i );

	  		echo ("<". $tag. ">". odbc_result($result,$i). "</". $tag. ">\n");


    	echo ("</tablerow>\n\n");


	echo ("</result>");

	//close the connection 

	odbc_close ($conn); 


else echo "odbc not connected"; 


Open in new window

Question by:fantasycommish

    Author Comment

    I would normally think this would error because of some sort of data type issue. This query works in SQL.

    Accepted Solution

    I figured out the problem. Needed a ; at the end of the query.

    [901-GeoState] ON [900-GeoCountry].[900_UNID] = [901-GeoState].[901_CountryID]"  <---- ;

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Javascript: Crash Course

    Javascript is not only emerging as the most important language to know, it's flexibility is unique. With Javascript being deployed on the web, mobile and even the desktop this is the one language that all technologists need to know.

    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now