Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#46 2015-09-10 11:54:10

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

There is no official way for that. In that situation you probably don’t use the safe_ functions for the second DB and use only PHP mysql_ functions (where you specify which DB link to use), so either you keep it as is or switch to using mysqli_ functions if your hosting setup requires it.

Offline

#47 2015-09-10 12:05:49

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

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

ruud wrote #294644:

switch to using mysqli_ functions if your hosting setup requires it.

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.

Edit: could there be a safe_ function for this?

Last edited by etc (2015-09-10 12:08:21)

Offline

#48 2015-09-10 14:36:27

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,743
GitHub

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

ruud wrote #294638:

The mysqli stuff shouldn’t break many plugins.

This is pretty much what I’m getting at – it won’t be the end of days in Pluginland (it’s a place, really) if/when mysqli stuff is brought into play, but in the absence of a reasonably up-to-date or comprehensive list of all Textpattern plugins, supported or not, it’s an unknown quantity as to how many plugins will break. The high profile/active plugin developers around here will no doubt be on the case with modifications and updates as needed, which is encouraging, but other niche plugins might cause a problem.

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.

Offline

#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,681
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,681
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