guymclarenza Posted February 6, 2023 Share Posted February 6, 2023 $sqli= $pdo->query("SELECT * FROM pages WHERE page_website='".$site."' ORDER by page_id ASC LIMIT 0,1"); while ($rowi = $sqli->fetch()) { $bid=$rowi["page_id"]; $img=$rowi["page_img"]; $imga=$rowi["page_imgalt"]; $title=$rowi["page_title"]; $pge=$rowi["page_text"]; $pint=$rowi["page_intro"]; $ptop=$rowi["page_banner"]; $pvid=$rowi["page_video"]; $tags=$rowi["page_tags"]; $metadesc=$rowi["page_desc"]; $ontology=$rowi["page_onto"]; $ontodesc=$rowi["page_ontodesc"]; } Gives me this as a result on page. In my limited understanding it would seem that pdo->query no longer gives the desired results in php8. This works in php7. I seem to be too stupid to find why this is. Can anyone point me in the right direction please. Quote query("SELECT * FROM pages WHERE page_id='42' ORDER by page_id ASC LIMIT 0,1"); while ($rowi = $sqli->fetch()) { $bid=$rowi["page_id"]; $img=$rowi["page_img"]; $imga=$rowi["page_imgalt"]; $title=$rowi["page_title"]; $pge=$rowi["page_text"]; $pint=$rowi["page_intro"]; $ptop=$rowi["page_banner"]; $pvid=$rowi["page_video"]; $tags=$rowi["page_tags"]; $metadesc=$rowi["page_desc"]; $ontology=$rowi["page_onto"]; $ontodesc=$rowi["page_ontodesc"]; } include ("navigation/heada.php"); echo " "; echo ""; echo nl2br($pge); echo " "; echo " "; include ("navigation/lnav.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/315886-prepared-statement-fail-in-php8/ Share on other sites More sharing options...
ginerjm Posted February 6, 2023 Share Posted February 6, 2023 (edited) I don't see the "this" you refer to. How many records were returned? And please don't post code that is simply a flowing block of text. Very hard to read and make sense of. And if that is how you are writing your code I strongly suggest you change your style. And what is it you expect to see? And this is not using any prepared statements. Edited February 6, 2023 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/315886-prepared-statement-fail-in-php8/#findComment-1605436 Share on other sites More sharing options...
guymclarenza Posted February 6, 2023 Author Share Posted February 6, 2023 Yje flowing block of text is the this. Quote Link to comment https://forums.phpfreaks.com/topic/315886-prepared-statement-fail-in-php8/#findComment-1605437 Share on other sites More sharing options...
Barand Posted February 6, 2023 Share Posted February 6, 2023 1 hour ago, guymclarenza said: it would seem that pdo->query no longer gives the desired results in php8 FYI - pdo->query works fine in PHPv8 (provided your query is correct, of course). Quote Link to comment https://forums.phpfreaks.com/topic/315886-prepared-statement-fail-in-php8/#findComment-1605439 Share on other sites More sharing options...
ginerjm Posted February 6, 2023 Share Posted February 6, 2023 We seem to not be communicating very well Good luck. Quote Link to comment https://forums.phpfreaks.com/topic/315886-prepared-statement-fail-in-php8/#findComment-1605440 Share on other sites More sharing options...
Solution kicken Posted February 6, 2023 Solution Share Posted February 6, 2023 2 hours ago, guymclarenza said: Gives me this as a result on page If you're seeing the source code to your page displayed when you load it, then this is not some problem with prepared queries but a problem of your code not being parsed at all. This would either be due to PHP not being installed and configured correctly, or you using short tags and your PHP installation no longer being configured to allow them. Quote Link to comment https://forums.phpfreaks.com/topic/315886-prepared-statement-fail-in-php8/#findComment-1605441 Share on other sites More sharing options...
guymclarenza Posted February 14, 2023 Author Share Posted February 14, 2023 (edited) Thanks to everyone that tried to help, I have been busy with my real job. Making wooden stuff. I found the solution and my site now works under php8.1, hopefully I never need to do this again unless I feel like making a change. If you want to see the site it's at DustFactory <? wasn't doing it, I had to make all instances <?php Edited February 14, 2023 by guymclarenza Quote Link to comment https://forums.phpfreaks.com/topic/315886-prepared-statement-fail-in-php8/#findComment-1605638 Share on other sites More sharing options...
ginerjm Posted February 14, 2023 Share Posted February 14, 2023 (edited) Yes - <?php has been the norm for awhile now - just didn't cause a failure until recently. It has been the suggested format for some time. Glad you found it. Below is a (perhaps?) cleaner version of your code. Something that makes it a bit clearer (to me at least): // Always specify the column names you want to select, not just a *. // IMHO - define the query in a string var so that you can easily show it if necessary without having to re-type it. Perhaps you may // want to add it to an error output to see what it looks like during debugging. // $q = "SELECT page_id, page_img, page_imgalt, page_title, page_text, page_intro, page_baanner, page_video, page_tags, page_desc, page_onto, page_ontodesc FROM pages WHERE page_website = '$site' ORDER by page_id LIMIT 0,1"; if (!$qst = $pdo->query($q)) { echo "Error - query did not run"; //add error message output here too. exit(); } // process the results now while (list($id, $img, $imga, $title, $text, $int, $banner, $vid, $tags, $desc, $ontology, $ontodesc) = $qst->fetch(PDO::FETCH_NUM)) { // do your output work here with the vars (slightly modified) provided in the list() ... ... } Next step is to learn to use prepared queries, especially when inserting user-provided values in a query. Edited February 14, 2023 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/315886-prepared-statement-fail-in-php8/#findComment-1605641 Share on other sites More sharing options...
chesse18 Posted February 16, 2023 Share Posted February 16, 2023 I would try to help but it's difficult to make sense of the structure of your code there... Also, in the original post, those are not prepared statements. Quote Link to comment https://forums.phpfreaks.com/topic/315886-prepared-statement-fail-in-php8/#findComment-1605754 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.