News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Query stopped working

Started by Sir Osis of Liver, January 04, 2018, 06:43:01 PM

Previous topic - Next topic

Sir Osis of Liver

Today isn't my day. >:(  Been using this query in Subs.php for several years, now it stopped working. 



$result = $smcFunc['db_query']('','
SELECT MAX(last_pic_date)
FROM {db_prefix}gallery_cat');

$row = mysql_fetch_array($result);
$last_pic_date = $row['MAX(last_pic_date)'];



$last_pic_date is always null.


Crap, should have posted this in coding, can someone move it? :P


Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Arantor

Well, yeah, because SMF stopped using the ancient library, not to mention not supporting the singularly most inefficient way to get data (do you really need two copies of every item in the array?)

Let's do it in a little more efficient way, and clean up after ourselves afterwards.


$result = $smcFunc['db_query']('','
SELECT MAX(last_pic_date)
FROM {db_prefix}gallery_cat');

list($last_pic_date) = $smcFunc['db_fetch_row']($result);
$smcFunc['db_free_result']($result);

Sir Osis of Liver

Thanks, will try that when I'm back on my computer tomorrow.  Been using it for years, what would have caused it stop working?
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

vbgamer45

Upgrading to new version of PHp 7.0.x or higher.
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Sir Osis of Liver

I'm running php 5.6.32.  Only thing that's changed is I recently upped from 2.0.13 -> .15.  Will try Arantor's code soon as I get a chance.  That query has been in use about 3 1/2 years.

Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Arantor

And 2.0.14 replaced out the guts of $smcFunc. If you'd used $smcFunc consistently it would have continued to work without problem.

Sir Osis of Liver

Don't really remember, but I would have cobbled together that query from similar core code, so it should be consistent with what was in use at the time (2014).  Just tried your code, it works.  Now have to see if it times out correctly.
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Arantor

There is absolutely no core code in 2.0 that uses mysql_ bare functions outside of where $smcFunc sets them up, and nowhere uses fetch_array because it's inefficient.

Sir Osis of Liver

Hmm, don't know enough about mysql to have written that code from scratch, maybe got it off stackoverflow.  Anyway, it's working again, thanks for the assist.
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Advertisement: