You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/audit-config-file.rst
+20-13Lines changed: 20 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -281,7 +281,7 @@ Recording the state of the row.
281
281
Example 4: Database Session
282
282
:::::::::::::::::::::::::::
283
283
284
-
Recording the database session (a single connection by a client). See :ref:`additional-sql-section` for setting the variable ``@audit_uuid``.
284
+
Recording the database session (a single connection from your PHP application to the MySQL instance). See :ref:`additional-sql-section` for setting the `user defined variable <https://mariadb.com/kb/en/user-defined-variables/>`_ ``@audit_uuid`` in MySQL.
285
285
286
286
.. code-block:: json
287
287
@@ -292,6 +292,11 @@ Recording the database session (a single connection by a client). See :ref:`addi
292
292
"column_type": "bigint(20) unsigned not null",
293
293
"expression": "@audit_uuid"
294
294
}
295
+
],
296
+
"additional_sql": [
297
+
"if (@audit_uuid is null) then",
298
+
" set @audit_uuid = uuid_short();",
299
+
"end if;",
295
300
]
296
301
}
297
302
@@ -300,7 +305,7 @@ Recording the database session (a single connection by a client). See :ref:`addi
300
305
Example 5: Order
301
306
::::::::::::::::
302
307
303
-
Recording the order of the data changes. See :ref:`additional-sql-section` for setting the variable ``@audit_rownum``.
308
+
Recording the order of the data changes. See :ref:`additional-sql-section` for setting the `user defined variable <https://mariadb.com/kb/en/user-defined-variables/>`_ ``@audit_rownum`` in MySQL.
304
309
305
310
.. code-block:: json
306
311
@@ -311,6 +316,9 @@ Recording the order of the data changes. See :ref:`additional-sql-section` for s
@@ -345,17 +353,17 @@ Recording the session ID. This example is useful tracking data changes made in m
345
353
{
346
354
"column_name": "audit_ses_id",
347
355
"column_type": "int(10) unsigned",
348
-
"expression": "@abc_g_ses_id"
356
+
"expression": "@audit_ses_id"
349
357
}
350
358
]
351
359
}
352
360
353
-
When retrieving the session you must set the variable MySQL ``@abc_g_ses_id`` in your web application.
361
+
When retrieving the session you must set the `user defined variable <https://mariadb.com/kb/en/user-defined-variables/>`_ ``@audit_ses_id`` in MySQL from your PHP application. See :ref:`setting-user-defined-variables-in-mysql` for examples of setting `user defined variables <https://mariadb.com/kb/en/user-defined-variables/>`_ in MySQL.
354
362
355
363
Example 8: End User
356
364
:::::::::::::::::::
357
365
358
-
Recording the user ID. This example is useful recording the end user who has modified the data in your (web) application.
366
+
Recording the user ID. This example is useful for recording the end user who has modified the data using your PHP application.
359
367
360
368
.. code-block:: json
361
369
@@ -364,12 +372,12 @@ Recording the user ID. This example is useful recording the end user who has mod
364
372
{
365
373
"column_name": "audit_usr_id",
366
374
"column_type": "int(10) unsigned",
367
-
"expression": "@abc_g_usr_id"
375
+
"expression": "@audit_usr_id"
368
376
}
369
377
]
370
378
}
371
379
372
-
When retrieving the session and when signing in you must set the variable MySQL ``@abc_g_usr_id`` in your (web) application.
380
+
When retrieving the session and when signing in or off you must set the `user defined variable <https://mariadb.com/kb/en/user-defined-variables/>`_ ``@audit_usr_id`` in MySQL from your PHP application. See :ref:`setting-user-defined-variables-in-mysql` for examples of setting `user defined variables <https://mariadb.com/kb/en/user-defined-variables/>`_ in MySQL.
373
381
374
382
.. _additional-sql-section:
375
383
@@ -381,7 +389,7 @@ The additional SQL section specifies additional SQL statements that are placed a
381
389
Example
382
390
```````
383
391
384
-
This example show how to set the variables ``@audit_uuid`` and ``@audit_rownum`` mentioned in :ref:`example_database_session` and :ref:`example_order`.
392
+
This example show how to set the variables ``@audit_uuid`` and ``@audit_rownum`` mentioned in sections :ref:`example_database_session` and :ref:`example_order`.
385
393
386
394
.. code-block:: json
387
395
@@ -450,21 +458,20 @@ An audit trail will be recorded for table ``FOO_USER``.
450
458
"FOO_USER": {
451
459
"audit": true,
452
460
"alias": "usr",
453
-
"skip": "@g_skip_foo_user"
461
+
"skip": "@audit_skip_foo_user"
454
462
}
455
463
}
456
464
}
457
465
458
-
When MySQL variable ``@g_skip_foo_user`` no audit triggers will record a data change. In the SQL code below updating column ``usr_last_login`` will not be recorded.
466
+
When `user defined variable <https://mariadb.com/kb/en/user-defined-variables/>`_ ``@audit_skip_foo_user`` in MySQL is set no audit triggers will record data changes. In the SQL code below updating column ``usr_last_login`` will not be recorded.
Copy file name to clipboardExpand all lines: docs/miscellaneous.rst
+32Lines changed: 32 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,6 +42,38 @@ If your application is querying on tables in the ``audit schema`` you are free t
42
42
43
43
Be careful with unique indexes. A key of a table in the ``data schema`` will (very likely) not be a key of the corresponding table in the ``audit schema``.
44
44
45
+
.. _setting-user-defined-variables-in-mysql:
46
+
47
+
Setting User Defined Variables in MySQL
48
+
---------------------------------------
49
+
50
+
There are several ways for setting user defined variables in MySQL from your PHP application. In this section we discuss two methods. More information about user defined variables in MySQL can be found at `https://mariadb.com/kb/en/user-defined-variables/ <https://mariadb.com/kb/en/user-defined-variables/>`_ and `https://dev.mysql.com/doc/refman/8.0/en/user-variables.html <https://dev.mysql.com/doc/refman/8.0/en/user-variables.html>`_
51
+
52
+
Explicit Query From PHP
53
+
```````````````````````
54
+
55
+
The PHP snippet below is an example of setting a user defined variable in MySQL from a PHP application.
56
+
57
+
.. code-block:: PHP
58
+
59
+
// User has signed in and variable $usrId holds the ID of the user and
The SQL statement below is an example of setting user defined variables in MySQL in a SQL statement (in this example session data is stored in table `FOO_SESSION`).
67
+
68
+
.. code-block:: php
69
+
70
+
select @audit_ses_id := ses_id
71
+
, @audit_usr_id := usr_id
72
+
, ses_data
73
+
from FOO_SESSION
74
+
where ses_token = 'the-long-token-stored-in-the-session-cookie-of-the-user-agent'
0 commit comments