Advertisement:

Author Topic: Query stopped working  (Read 417 times)

Offline Sir Osis of Liver

  • SMF Hero
  • ******
  • Posts: 7,346
  • There's someone in my head but it's not me.
Query stopped working
« on: January 04, 2018, 06:43:01 PM »
Today isn't my day. >:(  Been using this query in Subs.php for several years, now it stopped working. 

Code: [Select]

$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



Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 68,361
    • Arantor on GitHub
Re: Query stopped working
« Reply #1 on: January 04, 2018, 07:12:20 PM »
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.

Code: [Select]
$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);
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

You either die a hero or live long enough to see yourself become the villain. It seems you have chosen which, and now I must do the same.

Offline Sir Osis of Liver

  • SMF Hero
  • ******
  • Posts: 7,346
  • There's someone in my head but it's not me.
Re: Query stopped working
« Reply #2 on: January 04, 2018, 11:06:26 PM »
Thanks, will try that when I'm back on my computer tomorrow.  Been using it for years, what would have caused it stop working?

Offline vbgamer45

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 19,485
    • smfhacks on Facebook
    • VBGAMER45 on GitHub
    • @createaforum on Twitter
    • SMF For Free
Re: Query stopped working
« Reply #3 on: January 05, 2018, 01:14:10 AM »
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

Offline Sir Osis of Liver

  • SMF Hero
  • ******
  • Posts: 7,346
  • There's someone in my head but it's not me.
Re: Query stopped working
« Reply #4 on: January 05, 2018, 12:09:38 PM »
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.


Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 68,361
    • Arantor on GitHub
Re: Query stopped working
« Reply #5 on: January 05, 2018, 12:21:08 PM »
And 2.0.14 replaced out the guts of $smcFunc. If you'd used $smcFunc consistently it would have continued to work without problem.
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

You either die a hero or live long enough to see yourself become the villain. It seems you have chosen which, and now I must do the same.

Offline Sir Osis of Liver

  • SMF Hero
  • ******
  • Posts: 7,346
  • There's someone in my head but it's not me.
Re: Query stopped working
« Reply #6 on: January 05, 2018, 12:36:38 PM »
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.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 68,361
    • Arantor on GitHub
Re: Query stopped working
« Reply #7 on: January 05, 2018, 12:39:23 PM »
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.
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

You either die a hero or live long enough to see yourself become the villain. It seems you have chosen which, and now I must do the same.

Offline Sir Osis of Liver

  • SMF Hero
  • ******
  • Posts: 7,346
  • There's someone in my head but it's not me.
Re: Query stopped working
« Reply #8 on: January 05, 2018, 09:24:41 PM »
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.