Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "J.O. Aho" Newsgroups: comp.lang.php Subject: Re: Help With Warning Message Date: Tue, 24 Aug 2021 00:33:43 +0200 Lines: 44 Message-ID: References: <7no5igtt055jqdalqa2u2vlkfeu6bvhnag@4ax.com> <8ia6ig94heh1gjujblafvn17or10ufdlik@4ax.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net Cl7FaIe7w8Xykn70mnqIeA2ZCLLgsm5H9pT2tptqyeSh7sY353 Cancel-Lock: sha1:5wjEFYcaM3RuUcYEo0eLQ3ri6vk= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 In-Reply-To: Content-Language: en-US-large Xref: csiph.com comp.lang.php:18778 On 23/08/2021 20.19, Lew Pitcher wrote: > And, to be complete, the OP should check the value in $result4 > before invoking the fetch() method. So the logic fragment should > look more like > $result4 = $dbh->query($query4); > if ($result4 === FALSE) > { > /* query() failed for some reason - abort this activity */ > } > else > { > $da = $result4->FETCH(PDO::FETCH_ASSOC); > if ($da === FALSE) > { > /* fetch() failed for some reason - abort this activity */ > } > else $da_name = $da['airport_name']; > } > Make the code even better (and more readable), we should skip the else-part $result4 = $dbh->query($query4); if ($result4 === FALSE) { throw new Exception("Query failed: " + $dbh->errorInfo()[2]); } $da = $result4->FETCH(PDO::FETCH_ASSOC); if ($da === FALSE) { throw new Exception("Fetch failed."); } $da_name = $da['airport_name']; Of course this requires you take care of the exception higher up in the code and give a nice general error message, log the exception. -- //Aho