2014-12-07 151 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()给这些字段赋值以插入。我有一个感觉地址,它允许换行,空格和逗号,在绑定时引起问题。我想知道你是否同意,如果有的话,你有一个解决方案吗?