-1

i'm trying to query for some data from a table here is the query i send to the pdo

$query ="select ads.adID from ads,ad_content where ads.adID=ad_content.adID  and city = amsterdam  and EXISTS(select 1 from ad_content where ad_content.name = air_conditioner and ad_content.value =1)";

here is the pdo function im using:

public function readDBNoStoredProcedure($query ,$arr=[])
    {
        //call the passed query and read not stored procedure
        self::connect();
        $statement = self::$connection->prepare($query);
        $check = $statement->execute($arr);

        if ($check) {
            /**
             * PDO::FETCH_OBJ : returns an anonymous object with property names that correspond 
             * to the column names returned in your result
             */
            $result = $statement->fetchAll(PDO::FETCH_OBJ);
            self::disconnect();
            if (is_array($result) && count($result) > 0) {
                return $result;
            }
            return false;
        }
        self::disconnect();
        return false;
    }

and the tables are like this for ads-

adId city
1 amsterdam
2 new york

and adContent is:

adId name value
1 air_conditioner 1
1 garden 0

the error is:

<b>Fatal error</b>:  Uncaught PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'amsterdam' in 'where clause' in C:\xxa\htdocs\home\api\system\classes\useDBs.php:151
Stack trace:
#0 C:\xxa\htdocs\home\api\system\classes\useDBs.php(151): PDOStatement-&gt;execute(Array)
#1 C:\xxa\htdocs\home\home-app\api.php(100): dbClass-&gt;readDBNoStoredProcedure('select ads.adID...', Array)
#2 C:\xxa\htdocs\home\home-app\api.php(349): getAdsIdThatFeetSearch()
#3 {main}
  thrown in <b>C:\xxa\htdocs\home\api\system\classes\useDBs.php</b> on line <b>151</b><br />
AD7six
  • 59,391
  • 12
  • 88
  • 120
hai mo
  • 1
  • 1
  • 1
    It would be a good idea to provide the exact error message you get, instead of vague and uncertain paraphrase. – Your Common Sense May 24 '22 at 09:42
  • `city = amsterdam` -> `city = 'amsterdam'`. P.S, Also, please learn how to do an INNER JOIN instead of the archaic comma-separated list of tables. – ADyson May 24 '22 at 10:06

0 Answers0