The old dog
The old dog

Reputation: 157

SQL Server vs MySQL and PHP vs ColdFusion

This query works fine with ColdFusion, yet I can't get it to work in PHP. The PHP doesn't like my joins. What is different in the two queries?

<cfquery name="getArt" datasource="mssqlcf_PDartist1">
select * from artwork a
join Categories b on (b.CID = a.CID)
join SubCategories c on (c.CID = b.CID and c.SCID = a.SCID)
where AID = #AID#
order by DisplayOrder
</cfquery>


<?php
$dbname = 'pdartist2';
$table = 'artwork';
$result = mysql_query("SELECT * from artwork") or die(mysql_error());
a join Categories b on (b.CID = a.CID)
join SubCategories c on (c.CID = b.CID and c.SCID = a.SCID)
where AID = $AID
order by DisplayOrder
mysql_free_result($result);
?>

Upvotes: 0

Views: 222

Answers (1)

Mark Byers
Mark Byers

Reputation: 838386

You ended the PHP string too early. The quotes must surround the entire SQL query:

$result = mysql_query("SELECT *
    FROM artwork a
    JOIN Categories b ON b.CID = a.CID
    JOIN SubCategories c ON c.CID = b.CID AND c.SCID = a.SCID
    WHERE AID = $AID
    ORDER BY DisplayOrder") or die(mysql_error());

Upvotes: 2

Related Questions