2014-12-07 149 views
1

我有我的機器上運行的WAMP(PHP版本5.5.12)。我的項目工程WAMP但是當我遠程服務器上運行的程序(PHP版本5.4.32)我收到以下錯誤:適用於WAMP,但不適用於遠程服務器

Array ([0] => 42S22 [1] => 1054 [2] => Unknown column 'address' in 'field list')

我試圖從一種形式傳遞信息到數據庫。我不知道這個問題是關係到下面輸入的形式:如果設置

Address:<br> <textarea name="address" rows="3" cols="25" WRAP="hard"><?php echo escape(Input::get('address')); ?> </textarea> 

輸入::得到($項目)返回$ _ POST [$項目。其他條目如下:

Last name: <input type="text" name="last_name" value="<?php echo escape(Input::get('last_name')); ?>"> 

並且不會產生問題。我曾嘗試使用print_r($ e-> errorInfo());在我的聲明中:

catch(Exception $ e) {die($ e-> getMessage()); }

但這不起作用。我不知道我是否正確使用它。有人可以提供一個建議。我會很感激。

回答

0

我認爲你還沒有更新你的數據庫。您嘗試從數據庫中獲取不存在的列。

因此,檢查您的地址是地址,並檢查字段是否正確。

0

非常感謝您的回覆。

QI think you haven't updated your database. You try to fetch a columns from your database which doesn't exist.

我檢查過,這不是問題所在。我認爲問題在於以下功能:

public function insert($table, $fields = array()) 
    { if(count($fields)) //true if $fields holds data 
    { $keys = array_keys($fields); 

     $values = ''; //to put inside query 

     $x = 1; 

     foreach($fields as $field) 
     { $values .= '?'; 
     if($x < count($fields)) 
     { $values .= ', '; 
     } 
     $x++; 
     } 
    $sql = "INSERT INTO {$table} (`".implode('`, `', $keys) . "`) VALUES({$values})"; 
     if(!$this->query($sql, $fields)->error()) 
     { return true; 
     } 
    } 
    return false; 
    } 

    public function query($sql, $darams = array()) 
    { 
    $this->_error = false; //reset error 
    if($this->_query = $this->_pdo->prepare($sql)) 
    { $x = 1; 
     if(count($darams)) 
     { foreach($darams as $param) 
     { $this->_query->bindValue($x, $param); 
      $x++; 
     } 
     } 
     if($this->_query->execute()) 
     { $this->_results = $this->_query->fetchAll(PDO::FETCH_OBJ); 
     $this->_count = $this->_query->rowCount(); 
     } 
     else  //an error has occured in SQL query 
     { $this->_error = true; 
     } 
    } 
    return $this; 
    } 

insert()through,$ values。='?';正在創建?作爲字段的值。 query()通過bindValue()給這些字段賦值以插入。我有一個感覺地址,它允許換行,空格和逗號,在綁定時引起問題。我想知道你是否同意,如果有的話,你有一個解決方案嗎?