Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
en:entwickler:datenbankzugriffsklasse [2015/11/04 22:59] – created thomas-rcven: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 //db_error// be called manually. In addition, the call tracking is improved. It will now be logged each script, and each row specified in which the error has occurred, based on the called script of the user. 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 //db_error// be called manually. In addition, the call tracking is improved. It will now be logged each script, and each row specified in which the error has occurred, based on the called script of the user.
  
-In addition to the error handling now also a logging of the SQL Views is installed. If the [[dedeveloper: 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: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.
  
 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>$sql    = "SELECT * FROM ". TBL_DATES; +<code php>$sql    = 'SELECT * FROM '. TBL_DATES; 
-$dates_result = mysql_query($sql, $g_adm_con); +$datesResult = mysql_query($sql, $g_adm_con); 
-db_error($dates_result,__FILE__,__LINE__);+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>$sql    = "SELECT * FROM ". TBL_DATES; +<code php>$sql    = 'SELECT * FROM '. TBL_DATES; 
-$dates_result = $gDb->query($sql);+$datesResult = $gDb->query($sql);
  
-while($row = $gDb->fetch_array($dates_result))+while ($row = $gDb->fetch_array($datesResult))
 { {
    ...    ...
 }</code> }</code>
  
-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.
  • en/entwickler/datenbankzugriffsklasse.1446674349.txt.gz
  • Last modified: 2015/11/04 22:59
  • by thomas-rcv