Login Retreive lost passwordRegister
Search

Forum Index / Feedback / [Suggestion] - MSSQL Fix

[ This topic is unsolved! ]

  Joao Correa 30 August 12 / 19:10  
Changed at 30 August 12 / 19:11
Hello, I made some modifications so that I could use with MSSQL 2000 database, I believe that these changes should have no consequences to others as MYSQL.

In class.dbFormHandler.php:

<?php
    
function _getQuery$table$data$sqlFields$edit$keys null )
    {
        
// get the field names from the table
        
$fieldNames $this->_db->getFieldNames$this->_table );
                
// get the keys field names from the table
                
$keys $this->_db->getPrKeys$this->_table );

        
// check if we got the fieldnames
        
if( !$fieldNames )
        {
            
trigger_error(
            
'Could not fetch the fieldnames of the table '$this->_table,
            
E_USER_WARNING
            
);
            return 
false;
        } 

        
// walk the data from the form
        
foreach( $data as $field => $value )
        {
            
// does the field exists in the table?
            
if( !in_array($field$fieldNames) )
            {
                
// field does not exists, remove it from the data array (we dont need it )
                
unset( $data[$field] );
            }
            
            
// does the PK field exists in the table?
            
elseif( in_array($field$keys) )
            {
                
// field exists, remove it from the data array (we dont need it )
                
unset( $data[$field] );
            }
            
            
// the field exists in the table
            
else
            {
                
// is the value an array? Implode it!
                
if( is_array($value) )
                {
                    
$value implode(', '$value);
                }

                
// remove spaces etc
                
$value trim$value );        

                
// if the value is not a SQL function...
                
if(!in_array($field$sqlFields) )
                {
                    
// escape the value for saving it into the database
                    
$value $this->_db->escapeString$value );

//                    // is the value a number or float?
//                    if( preg_match('/^-?\d*\.?\d+$/', $value))
//                    {
//                        // do we have to quote it ?
//                        if( $this->_db->quoteNumbers() )
//                        {
//                            $value = "'".$value."'";
//                        }
//                    }
//                    // the value is not a number.. just quote it
//                    else
//                    {
                        
$value "'".$value."'";
//                    }
                    // save the value. It's now db ready
                    
$data[$field] = $value;
                }
            }
        }

        
// check if there is still something left to save...
        
if( sizeof$data ) == )
        {
            return 
false;
        }

        
// if it's an edit form
        
if($edit)
        {
            
// generate the update query
            
$query 'UPDATE '.$this->_db->quote$this->_table )." SET \n";   

            
// walk all fields and add them to the query
            
foreach($data as $field => $value)
            {
                
$query .= ' '.$this->_db->quote$field ).' = '.$value.", \n";
            }

            
// add the where clause to the query
            
$query substr($query0, -3) . $this->_getWhereClause();           
            
            
        }
        
// the form is an insert form..
        
else
        {
            
// generate the insert query
            
$query 'INSERT INTO '.$this->_db->quote$this->_table )." (\n";
  
            
// add the field names to the query
            
foreach( array_keys($data) as $field )
            {
                
$query .= '  '$this->_db->quote$field ) .", \n";
            }

            
// add the values to the query
            
$query  substr($query0, -3) . ") VALUES (\n  ";
            
$query .= implode(",\n  "$data)."\n);";
        }        
        
// return the query
        
return $query;
    }
?>



In class.MSSQL.php:

<?php
    
function escapeString$string )
    {
        
//return preg_replace("'","''",$string);
        
return $string;
    }
?>


Please opine.
Best Regards,
Joao

  Johan Wiegel (Admin) 28 November 12 / 10:48  
Joao,

Sorry for the slow response, we have been very busy with projects for customers.

the changes in class.dbFormHandler.php can be achieved py putting

$this->_quoteNumbers = true; in the constructor in class.MSSQL.php.
So there is no need to make changes in class.dbFormHandel.php

But why no longer escaping in the fuinction escapestring.

(We don't have a MSSQL testing enviroment at the moment, so cannot test this change.)

  Top


powered by PHP-GLOBE   © 2004 - 2024 FormHandler. All rights reserved.   -   Open source license