Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php中的现有记录_Php_Postgresql - Fatal编程技术网

php中的现有记录

php中的现有记录,php,postgresql,Php,Postgresql,每当我在UI中添加新的位置/描述时,它都会自动保存到我的数据库中。我的问题是,我仍然可以添加一个地方,即使它已经存在。我所希望的是,如果新的描述/位置已经存在,它将不会保存/更新 任何建议都将不胜感激。 谢谢 这是我的编辑位置: public function executeEditPlaces(sfWebRequest $request) { try{ $id = pg_escape_string(strip_tags($request->getParameter("id")));

每当我在UI中添加新的位置/描述时,它都会自动保存到我的数据库中。我的问题是,我仍然可以添加一个地方,即使它已经存在。我所希望的是,如果新的描述/位置已经存在,它将不会保存/更新

任何建议都将不胜感激。 谢谢

这是我的编辑位置:

public function executeEditPlaces(sfWebRequest $request)
{
 try{
 $id  = pg_escape_string(strip_tags($request->getParameter("id")));

 // $id  = $request->getParameter("id");
 $query = "select description from country.regions where id = ('$id')";
    // die($query);


    $result=$this->conn->fetchAll($query);

    if(count($result)>0){

    $v = $result[0];
    $data['data'] = array('description' => $this->formatString($v['description']));
    }


    $data['success']=true;
    $data['msg']=$msg;
    die(json_encode($data));

  }
  catch(exception $e)
  {     
    $data['success']=false;
    $data['msg']=$e->getMessage();
    die(json_encode($data));
  }
}
这是我的更新位置:

public function executeUpdatePlaces(sfWebRequest $request)
{
 try{
 $by = $_SESSION['employee_id'];
 $now = date("Y-m-d H:I:s");

 $id  = $request->getParameter("id");
 $description  = pg_escape_string(strip_tags($request->getParameter("description")));

$description = trim($description);

 if(strlen($description) == 0)
 {
    die('cannot be empty');
 }  
 else
    {

$query = "update country.regions set description=('$description'),modified_by=('$by'),date_modified=('$now') where id=('$id')";

    $msg = "Existing Region Successfully Updated.";


    $this->conn->execute($query);
    $data['success']=true;
    $data['msg']=$msg;
    die(json_encode($data));
    }
  }
  catch(exception $e)
  {     
    $data['success']=false;
    $data['msg']=$e->getMessage();
    die(json_encode($data));
  }     

}
有两种方法:

  • 您可以更改表格,使列唯一

    更改忽略表country.regions添加唯一(说明)

  • 使用选择按钮检查您的描述/位置是否已存在

    $query = "select description from country.regions";
    $result=$this->conn->fetchAll($query);
    if(count($result)>0){
        print 'already exist'  
    } else {
        //insert code
    }
    
  • 有两种方法:

  • 您可以更改表格,使列唯一

    更改忽略表country.regions添加唯一(说明)

  • 使用选择按钮检查您的描述/位置是否已存在

    $query = "select description from country.regions";
    $result=$this->conn->fetchAll($query);
    if(count($result)>0){
        print 'already exist'  
    } else {
        //insert code
    }
    
  • 有两种方法:

  • 您可以更改表格,使列唯一

    更改忽略表country.regions添加唯一(说明)

  • 使用选择按钮检查您的描述/位置是否已存在

    $query = "select description from country.regions";
    $result=$this->conn->fetchAll($query);
    if(count($result)>0){
        print 'already exist'  
    } else {
        //insert code
    }
    
  • 有两种方法:

  • 您可以更改表格,使列唯一

    更改忽略表country.regions添加唯一(说明)

  • 使用选择按钮检查您的描述/位置是否已存在

    $query = "select description from country.regions";
    $result=$this->conn->fetchAll($query);
    if(count($result)>0){
        print 'already exist'  
    } else {
        //insert code
    }
    

  • 请检查重复条目的
    $description
    是否确实相同

    对于必须唯一的列,您可以在SQL模式中引入
    UNIQUE
    约束-它将在较低的层中引入安全性


    请检查说明是否为bytea类型
    bytea
    。如果是,应使用
    pg_escape_bytea
    而不是
    pg_escape_string
    请检查重复条目的
    $description
    是否确实相同

    对于必须唯一的列,您可以在SQL模式中引入
    UNIQUE
    约束-它将在较低的层中引入安全性


    请检查说明是否为bytea类型
    bytea
    。如果是,应使用
    pg_escape_bytea
    而不是
    pg_escape_string
    请检查重复条目的
    $description
    是否确实相同

    对于必须唯一的列,您可以在SQL模式中引入
    UNIQUE
    约束-它将在较低的层中引入安全性


    请检查说明是否为bytea类型
    bytea
    。如果是,应使用
    pg_escape_bytea
    而不是
    pg_escape_string
    请检查重复条目的
    $description
    是否确实相同

    对于必须唯一的列,您可以在SQL模式中引入
    UNIQUE
    约束-它将在较低的层中引入安全性


    请检查说明是否为bytea类型
    bytea
    。如果是,则应使用
    pg_escape_bytea
    而不是
    pg_escape_string

    使用
    unique
    约束更改数据库架构。是的,只需将描述/位置定义为唯一索引。@davidkonrad我必须在哪里定义唯一索引?@Mikel,请参阅下面的user1168095答案。我建议您使用PHPMyadmin这样的工具,创建索引非常容易。使用
    unique
    约束更改您的DB模式。是的,只需将description/place定义为唯一索引即可。@davidkonrad我必须在哪里定义唯一索引?@Mikel,请参阅下面的user1168095答案。我建议您使用PHPMyadmin这样的工具,创建索引非常容易。使用
    unique
    约束更改您的DB模式。是的,只需将description/place定义为唯一索引即可。@davidkonrad我必须在哪里定义唯一索引?@Mikel,请参阅下面的user1168095答案。我建议您使用PHPMyadmin这样的工具,创建索引非常容易。使用
    unique
    约束更改您的DB模式。是的,只需将description/place定义为唯一索引即可。@davidkonrad我必须在哪里定义唯一索引?@Mikel,请参阅下面的user1168095答案。我建议您使用PHPMyadmin这样的工具,在这里创建索引非常容易。