Advertisement:

Author Topic: Database Changes in SMF 2.0 - Part 2  (Read 140241 times)

Offline Grudge

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 10,742
  • Gender: Male
  • Unofficial nuisance
Re: Database Changes in SMF 2.0 - Part 2
« Reply #20 on: January 12, 2008, 09:53:49 AM »
Yes, the way for retrieving data is the same - only the way for doing a query is different. The other main change is that db_insert_id needs to be passed the table name and primary column to allow it to work on PostgreSQL, i.e:
Code: [Select]
$topicID = $smfFunc['db_insert_id']('{db_prefix}topics', 'id_topic');
I'm only a half geek really...

Offline Dannii

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 10,212
  • Mind the volcano!
    • curiousdannii on GitHub
Re: Database Changes in SMF 2.0 - Part 2
« Reply #21 on: January 12, 2008, 09:41:42 PM »
Okay thanks.
Can I ask what we should use instead of mysql_num_rows()?
"Never imagine yourself not to be otherwise than what it might appear to others that what you were or might have been was not otherwise than what you had been would have appeared to them to be otherwise."

Offline Thantos

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 16,163
  • Gender: Male
Re: Database Changes in SMF 2.0 - Part 2
« Reply #22 on: January 12, 2008, 10:34:09 PM »
$smfFunc['db_num_rows']()

For the most part you can take any mysql_* or db_* function and it'll follow the $smfFunc['db_*'] format.  I can't think of any exceptions off the top of my head.

Offline Sarge

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 6,209
  • Gender: Male
    • Zëri YT!
Re: Database Changes in SMF 2.0 - Part 2
« Reply #23 on: January 13, 2008, 12:02:40 PM »
Great post! Very well written and relatively easy to understand.

Mod authors and people who plan to integrate SMF 2.0 via SSI etc. should definitely check this out when SMF 2.0 comes out.
    Please do not PM me with support requests unless I invite you to.

http://www.zeriyt.com/   ~   http://www.galeriashqiptare.net/


Quote
<H> I had zero posts when I started posting

Offline Nao 尚

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,928
  • Gender: Male
    • wedgebook on Facebook
    • Wedge
Re: Database Changes in SMF 2.0 - Part 2
« Reply #24 on: January 13, 2008, 06:16:30 PM »
Single quotes are not allowed in queries....... Okay... But are double quotes allowed?
I've converted some stuff to the latest version and it uses a lot of queries with strings, so I just left them as they were, just replacing single quotes with double quotes, and double quotes with single quotes.

Something like,

Code: [Select]
$smfFunc['db_query']('', 'SELECT something FROM {db_prefix}hello WHERE stuff="' . $yo . '"');
I think it does work, though...
I will not make any deals with you. I've resigned. I will not be pushed, filed, stamped, indexed, briefed, debriefed or numbered.

Aeva Media rocks your life.

Offline Thantos

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 16,163
  • Gender: Male
Re: Database Changes in SMF 2.0 - Part 2
« Reply #25 on: January 13, 2008, 06:24:53 PM »
Well you can simply change it to
Code: [Select]
$smfFunc['db_query']('', 'SELECT something FROM {db_prefix}hello WHERE stuff={string:yo}', array('yo' => $yo)); and then not have to worry about it.

Offline Grudge

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 10,742
  • Gender: Male
  • Unofficial nuisance
Re: Database Changes in SMF 2.0 - Part 2
« Reply #26 on: January 13, 2008, 06:46:13 PM »
Not sure what the results of that would be Nao. MySQL normally expects strings to be enclosed in single quotes (In terms of mysql_real_escape_string etc) so you may end up getting odd results. Personally I'd just do as Thantos suggests...
I'm only a half geek really...

Offline Daniel15

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 4,222
  • Gender: Male
  • http://dan.cx/
    • daaniel on Facebook
    • Daniel15 on GitHub
    • daniel15 on LinkedIn
    • @Daniel15 on Twitter
    • Daniel15
Re: Database Changes in SMF 2.0 - Part 2
« Reply #27 on: January 14, 2008, 01:55:46 AM »
Looking good, I'm gonna have to update my mods soon :D
As for $smfFunc['db_insert'], how long has that been there for? I never noticed it :o
Daniel15, former Customisation team member, resigned due to lack of time. I still love everyone here :D.
Go to smfshop.com for SMFshop support, do NOT email or PM me!

Offline Aaron

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 6,711
  • Gender: Male
    • Aaronweb.net
Re: Database Changes in SMF 2.0 - Part 2
« Reply #28 on: January 14, 2008, 02:21:43 AM »
As for $smfFunc['db_insert'], how long has that been there for? I never noticed it :o

Since SMF 2.0 Alpha, if I recall correctly. It's been there for quite a while now, in any case. ;)

Offline JayBachatero

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 19,562
  • Gender: Male
    • @jaycreations on Twitter
    • JayBachatero.com
Re: Database Changes in SMF 2.0 - Part 2
« Reply #29 on: January 14, 2008, 04:00:46 AM »
That has been there since the early days of 2.0.  Back when the abstraction stuff started.
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

Offline Daniel15

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 4,222
  • Gender: Male
  • http://dan.cx/
    • daaniel on Facebook
    • Daniel15 on GitHub
    • daniel15 on LinkedIn
    • @Daniel15 on Twitter
    • Daniel15
Re: Database Changes in SMF 2.0 - Part 2
« Reply #30 on: January 14, 2008, 04:13:45 AM »
Oh... My bad :P
I've been using SMF 2.0 since the Alpha, but never went through the abstraction code in great detail...
Daniel15, former Customisation team member, resigned due to lack of time. I still love everyone here :D.
Go to smfshop.com for SMFshop support, do NOT email or PM me!

Offline Nao 尚

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,928
  • Gender: Male
    • wedgebook on Facebook
    • Wedge
Re: Database Changes in SMF 2.0 - Part 2
« Reply #31 on: January 14, 2008, 04:18:35 AM »
Not sure what the results of that would be Nao. MySQL normally expects strings to be enclosed in single quotes (In terms of mysql_real_escape_string etc) so you may end up getting odd results.
Hmm that's curious indeed. Never had any problems since last week at least... (When the new format was introduced.)
And I do check most of my pages regularly.
I'll try to change these to the new format anyway, progressively at least.
I will also have to make sure my strings are not escaped before they're passed to db_query... Or maybe I should just use mysql_query for these, I don't know.
« Last Edit: January 14, 2008, 04:26:25 AM by Nao 尚 »
I will not make any deals with you. I've resigned. I will not be pushed, filed, stamped, indexed, briefed, debriefed or numbered.

Aeva Media rocks your life.

Offline codenaught

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 14,653
  • Gender: Male
  • Formerly Known As akabugeyes
Re: Database Changes in SMF 2.0 - Part 2
« Reply #32 on: January 18, 2008, 09:33:23 PM »
I haven't personally yet did any code with the new query style yet, but from the looks of it it looks pretty nice and clean in my opinion. :) I love that it makes it more likely to be secure (lowers chances of an oversight). I've always been concerned myself about my mods having some hole in them. ;)
Dev Consultant
Former SMF Doc Coordinator

Offline Nao 尚

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,928
  • Gender: Male
    • wedgebook on Facebook
    • Wedge
Re: Database Changes in SMF 2.0 - Part 2
« Reply #33 on: January 19, 2008, 03:55:49 AM »
Yeah... It's great, indeed. Takes a while to get used to, but it really makes the programmer feel better after a while ;)
And when you need speed, you can use the "security_disable" flag, or just rely on mysql_query (if you're using MySQL ;))... This is really good policy.

Apart from that $smfFunc['db_query']('you_bet') and then $smcFunc['db_query']('my_ass'), of course..........
I will not make any deals with you. I've resigned. I will not be pushed, filed, stamped, indexed, briefed, debriefed or numbered.

Aeva Media rocks your life.

Offline ByLegenS

  • Semi-Newbie
  • *
  • Posts: 20
  • Gender: Male
Re: Database Changes in SMF 2.0 - Part 2
« Reply #34 on: January 21, 2008, 05:00:41 AM »
thanks.

Offline JayBachatero

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 19,562
  • Gender: Male
    • @jaycreations on Twitter
    • JayBachatero.com
Re: Database Changes in SMF 2.0 - Part 2
« Reply #35 on: January 22, 2008, 03:04:47 AM »
Earl > Bertie :P
Umm I just noticed the phpBB's mascot is named Bertie.  http://www.phpbb.com/shop/
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

Offline Thantos

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 16,163
  • Gender: Male
Re: Database Changes in SMF 2.0 - Part 2
« Reply #36 on: January 22, 2008, 08:37:44 AM »
See again, more proof that Earl > Bertie :P

Offline Ben_S

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 11,725
  • xxx
Re: Database Changes in SMF 2.0 - Part 2
« Reply #37 on: January 22, 2008, 09:08:56 AM »
Converted my custom stuff a few days back, the one that got me was {$db_prefix} to {db_prefix}, looked for ages and couldn't see where my error was coming from. As with most things leave it for an hour or so then come back and you spot it straight away.

Now it's just a shame I can't do the actual upgrade for a little while due to the amount of traffic I'm getting at the mo.
Liverpool FC Forum with 14 million+ posts.

Offline Grudge

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 10,742
  • Gender: Male
  • Unofficial nuisance
Re: Database Changes in SMF 2.0 - Part 2
« Reply #38 on: January 22, 2008, 05:58:10 PM »
Ben,

I have to say it's going to be a bit scary when you upgrade your site to SMF 2.0. I think it will be the first proper comparison of 2.0 vs 1.1 performance as your site probably runs up to 99% capacity so if SMF 2.0 is only 5% slower than 1.1 it's really going to show.

Will certainly be interesting :D
I'm only a half geek really...

Offline Sverre

  • Sr. Member
  • ****
  • Posts: 748
Re: Database Changes in SMF 2.0 - Part 2
« Reply #39 on: February 01, 2008, 02:46:11 PM »
Where's your confidence, man?!? :P

What would you do if it turns out there is a (significant) performance regression between 1.1x and 2.0?