Commit 4306f6fd2e2c0274f554e96ac399cc60922e83a8
1 parent
8016c130
Added reference to database type.
Added db quoting library functions. git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@2913 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
2 changed files
with
73 additions
and
2 deletions
lib/database/db.inc
| 1 | <?php | 1 | <?php |
| 2 | +require_once("$default->fileSystemRoot/phplib/db_" . $default->dbType .".inc"); | ||
| 3 | +require_once("$default->fileSystemRoot/lib/database/escape.inc"); | ||
| 2 | /** | 4 | /** |
| 3 | * $Id$ | 5 | * $Id$ |
| 4 | * | 6 | * |
| @@ -28,7 +30,8 @@ class Database extends DB_Sql { | @@ -28,7 +30,8 @@ class Database extends DB_Sql { | ||
| 28 | 30 | ||
| 29 | /** Class name */ | 31 | /** Class name */ |
| 30 | var $classname = "Database"; | 32 | var $classname = "Database"; |
| 31 | - | 33 | + /** Database type */ |
| 34 | + var $databaseType = "mysql"; | ||
| 32 | /** Host name. Retrieved from config/environment.php */ | 35 | /** Host name. Retrieved from config/environment.php */ |
| 33 | var $Host = ""; | 36 | var $Host = ""; |
| 34 | /** Database name */ | 37 | /** Database name */ |
| @@ -53,8 +56,8 @@ class Database extends DB_Sql { | @@ -53,8 +56,8 @@ class Database extends DB_Sql { | ||
| 53 | $this->Database = $default->dbName; | 56 | $this->Database = $default->dbName; |
| 54 | $this->User = $default->dbUser; | 57 | $this->User = $default->dbUser; |
| 55 | $this->Password = $default->dbPass; | 58 | $this->Password = $default->dbPass; |
| 59 | + $this->databaseType = $default->dbType; | ||
| 56 | } | 60 | } |
| 57 | - // END wes changes | ||
| 58 | 61 | ||
| 59 | /** | 62 | /** |
| 60 | * Create a query from the provided paramaters. The ID column | 63 | * Create a query from the provided paramaters. The ID column |
lib/database/escape.inc
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * $Id$ | ||
| 5 | + * | ||
| 6 | + * Handles database value escaping. | ||
| 7 | + * | ||
| 8 | + * Copyright (c) 2003 Jam Warehouse http://www.jamwarehouse.com | ||
| 9 | + * | ||
| 10 | + * This program is free software; you can redistribute it and/or modify | ||
| 11 | + * it under the terms of the GNU General Public License as published by | ||
| 12 | + * the Free Software Foundation; either version 2 of the License, or | ||
| 13 | + * (at your option) any later version. | ||
| 14 | + * | ||
| 15 | + * This program is distributed in the hope that it will be useful, | ||
| 16 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 18 | + * GNU General Public License for more details. | ||
| 19 | + * | ||
| 20 | + * You should have received a copy of the GNU General Public License | ||
| 21 | + * along with this program; if not, write to the Free Software | ||
| 22 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 23 | + * | ||
| 24 | + * @version $Revision$ | ||
| 25 | + * @author Michael Joseph, Jam Warehouse (Pty) Ltd, South Africa | ||
| 26 | + */ | ||
| 27 | + | ||
| 28 | +/** | ||
| 29 | + * Apply stripslashes recursively. | ||
| 30 | + * [From php.net/mysql-real-escape-string] | ||
| 31 | + */ | ||
| 32 | +function stripslashes_deep($value) { | ||
| 33 | + $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value); | ||
| 34 | + return $value; | ||
| 35 | +} | ||
| 36 | +/** | ||
| 37 | + * Quote a variable to make it safe for rdbms processing. | ||
| 38 | + * This includes some SQL injection combatting side-effects. | ||
| 39 | + * [From php.net/mysql-real-escape-string] | ||
| 40 | + */ | ||
| 41 | +//TODO: add tablename/fieldname escaping function from forum.pear:db | ||
| 42 | +// move to pear::db in the medium term, instead of implementing XSS,sql injection prevention code | ||
| 43 | +function quote($value) { | ||
| 44 | + global $default; | ||
| 45 | + // Stripslashes if we need to | ||
| 46 | + if (get_magic_quotes_gpc()) { | ||
| 47 | + $value = stripslashes_deep($value); | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + if (is_numeric($value)) { | ||
| 51 | + return $value; | ||
| 52 | + } elseif (is_bool($value)) { | ||
| 53 | + return $value ? 1 : 0; | ||
| 54 | + } elseif (is_null($value)) { | ||
| 55 | + return 'NULL'; | ||
| 56 | + } else { | ||
| 57 | + // only use the mysql api function if we're using mysql | ||
| 58 | + // ??: is the api function still available to php if its not compiled in | ||
| 59 | + // ??: it is in by default isn't it? | ||
| 60 | + if ($default->dbType == "mysql") { | ||
| 61 | + $value = "'" . mysql_real_escape_string($value) . "'"; | ||
| 62 | + } else { | ||
| 63 | + $value = "'" . addslashes($value) . "'"; | ||
| 64 | + } | ||
| 65 | + return $value; | ||
| 66 | + } | ||
| 67 | +} | ||
| 68 | +?> | ||
| 0 | \ No newline at end of file | 69 | \ No newline at end of file |