Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#49 2015-09-10 14:56:24

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Let's decide what's actually going into 4.6

etc wrote #294645:

What should I replace global $DB; mysql_select_db($DB->db); with to make it both 4.5 and 4.6 compatible? It’s in a plugin, so hosting-independent.

Pseudo-code:

if (version_compare(get_pref('version'), '4.6', '>=')) {
  mysqli_select_db($DB, 'dbname');
} else {
  mysql_select_db('dbname');
}

Edit: could there be a safe_ function for this?

No. There isn’t one.

Offline

#50 2015-09-10 14:58:57

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Let's decide what's actually going into 4.6

gaekwad wrote #294671:

How about this – make a mysqli-test branch on Textpattern with the mysqli stuff and then test it against the top twenty plugins from the most active threads in the plugin forum. A few testers could divvy up the work of the top twenty, report back, and then snag some more plugins as time/energy/motivation permits.

It’s much easier than that. Just install the plugins in your current 4.5.7 TXP install, edit the plugin, search for “mysql_” functions. If you don’t find the string “mysql_” anywhere in the plugin, it’ll probably work in 4.6 (apart from the tag registry stuff, but for now that’s just a warning in debug mode).

Offline

#51 2015-09-10 19:52:22

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: Let's decide what's actually going into 4.6

ruud wrote #294677:

Pseudo-code:

Thanks. But I’m not sure it’s wise to use it right now, until we know the exact “mysqli switch” version. Something like if(is_callable('safe_select_db')) would be more robust.

Offline

#52 2015-09-10 20:13:43

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Let's decide what's actually going into 4.6

Turns out it’s a lot easier to check this reliably:

global $DB;
if (is_object($DB->link)) { 
  // use mysqli_
} else {
  // use mysql_
}

This works because $DB->link is a resource when using mysql_ functions, but it’s an object when using mysqli_;

Offline

#53 2015-09-10 20:16:30

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: Let's decide what's actually going into 4.6

Oh, great!

Offline

#54 2015-09-10 20:23:04

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Let's decide what's actually going into 4.6

We’ll have to find another trick if/once we switch to PDO instead of mysqli ;)

Offline

Board footer

Powered by FluxBB