Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
en:entwickler:datenbankzugriffsklasse [2015/11/04 22:59] – created thomas-rcv | en:entwickler:datenbankzugriffsklasse [2016/12/03 15:13] (current) – codestyle and typos ximex | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Database Access Class ====== | ====== Database Access Class ====== | ||
- | |||
Since version 2.0, there is now a class for database access. This class is similar to the table access classes of 2 parts. One general class **DB** and the respective extension, in our case **MySqlDb**. | Since version 2.0, there is now a class for database access. This class is similar to the table access classes of 2 parts. One general class **DB** and the respective extension, in our case **MySqlDb**. | ||
Line 6: | Line 5: | ||
Advantage of this new class is as a unified error handling. If an error occurs in the SQL statement, so a nicely formatted error message is now displayed automatically and must no longer, as before, the function // | Advantage of this new class is as a unified error handling. If an error occurs in the SQL statement, so a nicely formatted error message is now displayed automatically and must no longer, as before, the function // | ||
- | In addition to the error handling now also a logging of the SQL Views is installed. If the [[de: developer: php.ini_einstellungen # admidio debug flag|Admidio-debug flag]] is set and in the **php.ini** the PHP logging is enabled, you can now see in PHP logfile all SQL statements. Thus you can check the incorrect SQL statements and check which scripts have quite a lot of database accesses. | + | In addition to the error handling now also a logging of the SQL Views is installed. If the [[en:entwickler: |
Another advantage of the new classes is the easy connection to other databases. With relatively little effort Admidio can later also run on other databases. | Another advantage of the new classes is the easy connection to other databases. With relatively little effort Admidio can later also run on other databases. | ||
- | In the common.php a global object **$gDb** is defined for that class again, which can only access a MySQL database at the moment by default. The individual method calls are based on the previous MySQL function calls but only the //mysql_ // is missing before. | + | In the common.php a global object **$gDb** is defined for that class again, which can only access a MySQL database at the moment by default. The individual method calls are based on the previous MySQL function calls but only the //mysql_// is missing before. |
In code, the change looks like this: | In code, the change looks like this: | ||
**Previous Code** | **Previous Code** | ||
- | <code php> | + | <code php> |
- | $dates_result | + | $datesResult |
- | db_error($dates_result, | + | db_error($datesResult, __FILE__, __LINE__); |
- | while($row = mysql_fetch_array($dates_result)) | + | while ($row = mysql_fetch_array($datesResult)) |
{ | { | ||
... | ... | ||
Line 24: | Line 23: | ||
**New Code** | **New Code** | ||
- | <code php> | + | <code php> |
- | $dates_result | + | $datesResult |
- | while($row = $gDb-> | + | while ($row = $gDb-> |
{ | { | ||
... | ... | ||
}</ | }</ | ||
- | DThe Connection-ID must not be handed over, as this is managed in the class. Otherwise, all handovers are remained as it was in the original MySQL functions. | + | The Connection-ID must not be handed over, as this is managed in the class. Otherwise, all handovers are remained as it was in the original MySQL functions. |
If in the loop any additional SQL statements are executed, the resource ID(result) may not be transferred. Internally, the last will be automatically used. | If in the loop any additional SQL statements are executed, the resource ID(result) may not be transferred. Internally, the last will be automatically used. |