[Openfirst-cvscommit] base/config db_setup.php,NONE,1.1 dbase.php,1.26,1.27
Brought to you by:
xtimg
From: Astronouth7303 <ast...@us...> - 2005-05-25 01:46:06
|
Update of /cvsroot/openfirst/base/config In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9648/config Modified Files: dbase.php Added Files: db_setup.php Log Message: -Initial commit on DB maintainence class(es) -Removed last remenants of PEAR -added an escaping and some quoting functions Index: dbase.php =================================================================== RCS file: /cvsroot/openfirst/base/config/dbase.php,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** dbase.php 17 May 2005 01:55:57 -0000 1.26 --- dbase.php 25 May 2005 01:45:57 -0000 1.27 *************** *** 41,45 **** function ofirst_dbconnect($server = "", $username = "", $password = "", $newlink = "", $intclientflags = "") { ! global $dbasetype, $peardb, $connectdsn; if($dbasetype == "mysql") { if(function_exists("mysql_connect") == false) { --- 41,45 ---- function ofirst_dbconnect($server = "", $username = "", $password = "", $newlink = "", $intclientflags = "") { ! global $dbasetype, $connectdsn; if($dbasetype == "mysql") { if(function_exists("mysql_connect") == false) { *************** *** 72,76 **** function ofirst_select_db($databasename, $linkidentifier = "") { ! global $dbasetype, $peardb, $connectdsn; if($dbasetype == "mysql") { if(function_exists("mysql_select_db") == false) { --- 72,76 ---- function ofirst_select_db($databasename, $linkidentifier = "") { ! global $dbasetype, $connectdsn; if($dbasetype == "mysql") { if(function_exists("mysql_select_db") == false) { *************** *** 97,101 **** function ofirst_dberrno($linkidentifier = "") { ! global $dbasetype, $peardb; if($dbasetype == "mysql") { if(function_exists("mysql_errno") == false) { --- 97,101 ---- function ofirst_dberrno($linkidentifier = "") { ! global $dbasetype; if($dbasetype == "mysql") { if(function_exists("mysql_errno") == false) { *************** *** 126,130 **** function ofirst_dberror($linkidentifier = "") { ! global $dbasetype, $peardb; if($dbasetype == "mysql") { if(function_exists("mysql_error") == false) { --- 126,130 ---- function ofirst_dberror($linkidentifier = "") { ! global $dbasetype; if($dbasetype == "mysql") { if(function_exists("mysql_error") == false) { *************** *** 155,159 **** function ofirst_dbquery($string, $linkidentifier = "", $batchsize = "") { ! global $dbasetype, $peardb, $sqlconnection, $lastquery; $lastquery = "\$string = \"$string\", \$linkidentifier = \"$linkidentifier\", \$batchsize = \"$batchsize\""; --- 155,159 ---- function ofirst_dbquery($string, $linkidentifier = "", $batchsize = "") { ! global $dbasetype, $sqlconnection, $lastquery; $lastquery = "\$string = \"$string\", \$linkidentifier = \"$linkidentifier\", \$batchsize = \"$batchsize\""; *************** *** 189,193 **** function ofirst_dbfetch_object($resource, $rownumber = "") { ! global $dbasetype, $peardb; if($dbasetype == "mysql") { if(function_exists("mysql_fetch_object") == false) { --- 189,193 ---- function ofirst_dbfetch_object($resource, $rownumber = "") { ! global $dbasetype; if($dbasetype == "mysql") { if(function_exists("mysql_fetch_object") == false) { *************** *** 216,220 **** function ofirst_dbnum_rows($resource) { ! global $dbasetype, $peardb; if($dbasetype == "mysql") { if(function_exists("mysql_num_rows") == false) { --- 216,220 ---- function ofirst_dbnum_rows($resource) { ! global $dbasetype; if($dbasetype == "mysql") { if(function_exists("mysql_num_rows") == false) { *************** *** 244,248 **** function ofirst_dbname_version() { ! global $dbasetype, $peardb; if($dbasetype == "mysql") { $v = ofirst_dbfetch_object(ofirst_dbquery("SELECT VERSION() AS mysql_version")); --- 244,248 ---- function ofirst_dbname_version() { ! global $dbasetype; if($dbasetype == "mysql") { $v = ofirst_dbfetch_object(ofirst_dbquery("SELECT VERSION() AS mysql_version")); *************** *** 259,263 **** function ofirst_dbsize() { ! global $dbasetype, $peardb, $sqldatabase; if($dbasetype == "mysql") { $dbsize = 0; --- 259,263 ---- function ofirst_dbsize() { ! global $dbasetype, $sqldatabase; if($dbasetype == "mysql") { $dbsize = 0; *************** *** 278,281 **** --- 278,287 ---- function ofirst_dbcheck($linkidentifier = "") { #TODO: Write me! + global $dbasetype; + if($dbasetype == "mysql") { + } elseif($dbasetype == "mssql") { + } elseif($dbasetype == "odbc") { + } + exit(0); } *************** *** 357,360 **** return false; } ! } ?> --- 363,388 ---- return false; } ! } ! ! function ofirst_dbescape($text) { ! global $dbasetype; ! if($dbasetype == "mysql") { ! return mysql_real_escape_string($text); ! # MS SQL and ODBC don't have specific escaping functions. ! } else { ! # Lets just assume there isn't an escaping function ! return addslashes($text); ! } ! exit(0); ! } ! ! #Used for quoting field, table, and DB names ! function ofirst_dbquote_name($name) { ! return '`'.ofirst_dbescape($name).'`'; ! } ! ! #Used for quoting data ! function ofirst_dbquote_name($data) { ! return "'".ofirst_dbescape($data)."'"; ! } ?> --- NEW FILE: db_setup.php --- <?php /* * openFIRST.base - config/db_setup.php * * Copyright (C) 2005, * openFIRST Project * Original Author: Jamie Bliss <ja...@op...> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ // Purpose: Allow easy and stable configuration of database tables. This // includes both setup and modification of said tables. require_once('dbase.php'); /** An array of valid SQL types * This won't be used for checking */ $sqlValidTypes = array( /* After each type, there may be a list of options: * length - can have the form TYPE(###) * need length - must have the form TYPE(###) * length&digits - can have the form TYPE(###, ###) * length&bits - can have the form TYPE(###, ###) * length or digits - can have the form TYPE(###) or TYPE(###, ###) * * Any options not in this list refer to literal attributes */ # These are from phpMyAdmin 'VARCHAR', #need length, national, binary 'TINYINT', #length, unsigned, zerofill 'TEXT', #length 'DATE', 'SMALLINT', #length, unsigned, zerofill 'MEDIUMINT', #length, unsigned, zerofill 'INT', #length, unsigned, zerofill 'BIGINT', #length, unsigned, zerofill 'FLOAT', #need length, unsigned, zerofill OR #length&digits, unsigned, zerofill 'DOUBLE', #length&bits, unsigned, zerofill 'DECIMAL', #length or digits, unsigned, zerofill 'DATETIME', 'TIMESTAMP', #length(14,12,8,6) 'TIME', 'YEAR', #length(2,4) 'CHAR', #need length, national, binary, ascii, unicode OR #(none) 'TINYBLOB', 'TINYTEXT', 'BLOB', #length 'MEDIUMBLOB', 'MEDIUMTEXT', 'LONGBLOB', 'LONGTEXT', 'ENUM',#list of values 'SET',#list of values # These are additional types from the MySQL manual 'BIT', #length 'BOOL', 'BOOLEAN', 'INTEGER', #length, unsigned, zerofill 'DOUBLE PRECISION', #length&digits, unsigned, zerofill 'REAL', #length&digits, unsigned, zerofill 'DEC', #length or digits, unsigned, zerofill 'NUMERIC', #length or digits, unsigned, zerofill 'FIXED', #length or digits, unsigned, zerofill 'DATE', 'BINARY', #need length 'VARBINARY', #need length ); /** Gets an array of tables. * Uses the current DB connection. The key is the name, the content * is a Table class */ function GetTables() { # } /** The class representing a table. * This is a wrapper for a SQL table. It allows access to fields, * keys, etc. Note that it does not handle records, just structure. */ class Table { var $mName; /** Constructor */ function Table($Name) { # } /** Gets an array of current fields. * The returned array contains just the field names, in order. */ function getFields() { # } /** Adds a field to the table. * @param $Name The name of the new field * @param $Type The type of the new field * @param $Options An associative array of options. Certain elements * are required under certain conditions. */ function addField($Name, $Type, $Options=array()) { # } function getFieldType($Name) { # } function getFieldOptions($Name) { # } function alterField($Name, $Type, $Options) { # } } /*** SQL Statements ***/ /* Get information on a table: DESCRIBE `{TABLE NAME}` Which returns a series of "records" with the "fields": Field - some kind of string - Name Type - a type (with length and all) - data type Null - SET('YES') - whether it can be null Key - SET('MUL','PRI','UNI') - what kind of key it is Default - the same type as the field - the default value Extra - SET('auto_increment') - */ ?> |