Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2016-10-04 10:12:56

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,458
Website

Converting plugins to mysqli

There are a lot of threads about this at the moment so I’m consolidating the info here as a catch-all for how to update any plugin that uses mysql_* functions. You’ll know if a plugin does this because, depending on your PHP version, it’ll spit out errors or warnings such as:

access denied for user 'abc'@'localhost'

or:

Warning mysql_get_server_info(): A link to the server could not be established

or in PHP 7:

Fatal error: Uncaught Error: Call to undefined function mysql_connect() 

The problem stems from the fact that in Txp 4.6.0 we moved from using mysql_*() to mysqli_*() (note the ‘i’) functions as a stop-gap on our way towards PDO.

Any plugins that exclusively use the core’s safe_*() or get*() calls are immune to any issues. There are, however, a few PHP functions that plugin authors use directly, due to gaps in our API: mainly mysql_real_escape_string, mysql_get_server_info and mysql_error. To fix all three — and others — just do this:

  • In the plugin function that surrounds the mysql_*() call, ensure there is a global $DB; line somewhere near the top of the function.
  • Change the call name by adding an i after the mysql.
  • Add $DB->link as the first parameter to that call.
  • Repeat for all places where mysql_*() functions are used.

tl;dr example: convert:

mysql_real_escape_string($content);

to:

global $DB;
...
mysqli_real_escape_string($DB->link, $content);

and you’ll be on your way.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#2 2016-12-15 15:56:50

marisa1981
New Member
Registered: 2016-12-15
Posts: 1

Re: Converting plugins to mysqli

Hi! it is not working for my instalation (hak_tinymce), can you recomend to me some other similar plugin? I get kuo_tinymce_cdn but I can not add images directly.
Thank you!

Offline

#3 2016-12-16 14:17:45

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,152

Re: Converting plugins to mysqli

Hi, marisa1981, and welcome to the forum. hak_tinyMCE is the only WYSIWYG plugin with image connection to the textpattern DB. Sorry.

But can you tell us exactly what isn’t working, do you get errors, aren’t there no formatting buttons any longer displayed in the Write pane etc.?


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#4 2018-04-17 17:54:09

jayrope
Plugin Author
From: Berlin
Registered: 2006-07-06
Posts: 635
Website

Re: Converting plugins to mysqli

What, if a plugin only contains calls like
mysqli_affected_rows()
or mysqli_error()
- do we still have to fill in $DB->link
resulting in mysqli_affected_rows($DB->link)
or (EDIT) mysqli_error($DB->link) ,
and given that
global $DB; is involved in any of the respective functions, near the top of the respective function call?

Example from smd_user_manager v0.21.

Last edited by jayrope (2018-04-17 19:04:09)


a hole turned upside down is a dome, though only when there’s gravity.

Offline

#5 2018-04-17 18:34:10

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,458
Website

Re: Converting plugins to mysqli

Yes, same rules apply to those two functions: import $DB global once into the top of each function where the call is used, add the ‘i’ then stick the link in the brackets.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#6 2018-04-17 19:05:03

jayrope
Plugin Author
From: Berlin
Registered: 2006-07-06
Posts: 635
Website

Re: Converting plugins to mysqli

Perfekto, thanx again.


a hole turned upside down is a dome, though only when there’s gravity.

Offline

Board footer

Powered by FluxBB