Breaking Changes in v1.10.00: Difference between revisions

From XMBdocs
(Start new page.)
 
(→‎Queries: tablepre)
Line 32: Line 32:


If you wish to write similar query methods, the best practice is to create your own object class rather than try to modify the XMB service.
If you wish to write similar query methods, the best practice is to create your own object class rather than try to modify the XMB service.
=== The tablepre Variable ===
Instead of providing a global constant named <code>X_PREFIX</code>, XMB now stores the <code>$tablepre</code> variable from <code>config.php</code> as a property of the shared <code>vars</code> service.  The direct replacement in global scope is <code>$vars->tablepre</code> and it looks like this:
<pre>
$vars = \XMB\Services\vars();
$statement = 'SELECT * FROM' . $vars->tablepre . 'ranks';
</pre>

Revision as of 10:49, 2 January 2025

Customizing and migrating to v1.10.00 will require some new changes.

Queries

There are three main changes that affect all database queries in XMB.

Global $db Service Locator

Instead of providing a global variable named $db, XMB now offers two services named db and sql.

For a direct replacement of the global shared object reference, just add this near the top of your file:

$db = \XMB\Services\db();

If you need to create a 2nd database connection (to a different account or server) within your script, then use the revised class name instead:

$db2 = new \XMB\MySQLiDatabase(debug: false, logErrors: true);
$db2->connect(...);

Internally, XMB is starting to use methods of the shared sql service instead of direct or prepared statements. This results in cleaner and more secure code. For example, to get the shared service and check your inbox:

$sql = \XMB\Services\sql();
$vars = \XMB\Services\vars();

$msgCount = $sql->countU2UInbox($vars->self['username']);

If you wish to write similar query methods, the best practice is to create your own object class rather than try to modify the XMB service.

The tablepre Variable

Instead of providing a global constant named X_PREFIX, XMB now stores the $tablepre variable from config.php as a property of the shared vars service. The direct replacement in global scope is $vars->tablepre and it looks like this:

$vars = \XMB\Services\vars();

$statement = 'SELECT * FROM' . $vars->tablepre . 'ranks';