Pelzini

This is the code documentation for the Pelzini project

source of /viewer/database_mysql.php

The MySQL wrapper functions
  1. <?php
  2. /*
  3. Copyright 2008 Josh Heidenreich
  4.  
  5. This file is part of Pelzini.
  6.  
  7. Pelzini is free software: you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation, either version 3 of the License, or
  10. (at your option) any later version.
  11.  
  12. Pelzini is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Pelzini. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20.  
  21. /**
  22.  * The MySQL wrapper functions
  23.  * @package Viewer
  24.  * @author Josh Heidenreich
  25.  * @since 0.2
  26.  **/
  27.  
  28.  
  29. /**
  30.  * Connects to the MySQL database
  31.  **/
  32. function db_connect($settings)
  33. {
  34. global $db_connection;
  35.  
  36. if (!function_exists('mysql_connect')) {
  37. die('Unable to connect to database because "mysql" extension is not available');
  38. }
  39.  
  40. $db_connection = @mysql_connect(
  41. $settings['server'],
  42. $settings['username'],
  43. $settings['password']
  44. );
  45.  
  46. mysql_select_db($settings['name'], $db_connection);
  47. }
  48.  
  49.  
  50. /**
  51.  * Makes a query to the MySQL database
  52.  **/
  53. function db_query($q)
  54. {
  55. return mysql_query($q);
  56. }
  57.  
  58.  
  59. /**
  60.  * Escapses a string for use by the MySQL database
  61.  **/
  62. function db_escape($str)
  63. {
  64. }
  65.  
  66.  
  67. /**
  68.  * Quotes a string as nessasary for use by hte MySQL database
  69.  * The result will be different depending on the type of the input.
  70.  * - a number will be left as is
  71.  * - a string will be quoted
  72.  * - a null value will be returned as NULL
  73.  **/
  74. function db_quote($str)
  75. {
  76. if ($str === null) {
  77. return 'NULL';
  78.  
  79. } else if (is_int($str)) {
  80. return $str;
  81.  
  82. } else {
  83. return "'" . mysql_real_escape_string($str) . "'";
  84. }
  85. }
  86.  
  87.  
  88. /**
  89.  * Fetches a MySQL result set as an associative array
  90.  **/
  91. function db_fetch_assoc($res)
  92. {
  93. return mysql_fetch_assoc($res);
  94. }
  95.  
  96.  
  97. /**
  98.  * Returns the number of rows in a MySQL result set
  99.  **/
  100. function db_num_rows($res)
  101. {
  102. return @mysql_num_rows($res);
  103. }
  104.  
  105.  
  106. /**
  107.  * Returns the number of rows affected by the last MySQL query that was executed
  108.  **/
  109. function db_affected_rows($res)
  110. {
  111. }
  112.  
  113.  
  114. /**
  115.  * Returns the last unique ID generated by a query
  116.  **/
  117. function db_insert_id()
  118. {
  119. return mysql_insert_id();
  120. }
  121.  
  122.  
  123. ?>
  124.