Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.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 lastInsertId()导致程序崩溃_Php_Mysql - Fatal编程技术网

Php lastInsertId()导致程序崩溃

Php lastInsertId()导致程序崩溃,php,mysql,Php,Mysql,下面是这个函数。在最底层,我返回$this->conn->lastInsertId()。如果我没弄错的话,这应该是正确的 文件#1 如果我从文件#1中删除返回行并在文件#2中打印,则不会发生任何事情,程序也会像这样插入数据库。由于某种原因,此返回行导致整个程序失败,并导致404。很奇怪,我从来没有发生过这种情况,为什么这个返回线会导致这个错误呢 ==更新=== 更奇怪的是,我在我的文件中添加了以下项目 文件#1 我添加了一个新方法,并尝试打印它。我仍然得到文件404的错误。真奇怪。我希望这有助于

下面是这个函数。在最底层,我返回
$this->conn->lastInsertId()
。如果我没弄错的话,这应该是正确的

文件#1

如果我从文件#1中删除返回行并在文件#2中打印,则不会发生任何事情,程序也会像这样插入数据库。由于某种原因,此返回行导致整个程序失败,并导致404。很奇怪,我从来没有发生过这种情况,为什么这个返回线会导致这个错误呢

==更新===

更奇怪的是,我在我的文件中添加了以下项目 文件#1


我添加了一个新方法,并尝试打印它。我仍然得到文件404的错误。真奇怪。我希望这有助于解决问题,因为我被难倒了

错误日志中没有任何内容?我没有访问错误日志的权限,但除了404之外,它不会产生任何错误。它基本上没有命中文件哦,所以你不知道错误日志中是否有任何内容。如果不访问错误日志,就很难进行故障排除。您是否已打开所有错误报告?您的返回线路未完成。。lastInsertId是一个函数,括号和semikolon都丢失了…在打开

 public function insertData($table, $qty, $data){                                                                
    $errors = "";                                                                                            
    $columns = $this->fetchColumnNames($table);                                                              
    $column_list = implode(', ', $columns);                                                                  
    $values = array_fill(0, $qty, '?');                                                                           
    $value_list = implode(', ', $values);                                                                         
    $q = "INSERT INTO $table ($column_list) VALUES ($value_list)";                                                
    $stmt = $this->conn->prepare($q);                                                                             
    for($i = 1; $i < $qty + 1; $i++){                                                                             
        foreach($data as $key => $val){                                                                           
            if($key == $columns[$i-1]){                                                                           
                try{                                                                                              
                    if(is_numeric($val)){                                                                         
                        $stmt->bindValue($i, $val, PDO::PARAM_INT);                                              
                    }else{                                                                                        
                        $stmt->bindValue($i, $val, PDO::PARAM_STR);                                               
                    }                                                                                             
                }catch(PDOException $e){                                                                          
                    print  $e->getMessage();                                                                      
                }                                                                                                 
            }                                                                                                     
        }                                                                                                         
    }                                                                                                             
    try{                                                                                                          
        $stmt->execute();                                                                                         
    }catch(PDOException $e){                                                                                      
        $errors .=  $e->getMessage();                                                                             
        print $errors;                                                                                            
    }                                                                                                             
    return $this->conn->lastInsertId();
}
error_reporting(E_ALL);
ini_set('display_errors', 1);
include '../../inc/config.php';
include 'ProcessApplication/ProcessApplication.php';
include 'ProcessApplication/ProcessApplicationQuery.php';
$processor = new ProcessApplicationQuery($CONN);
$processor->insertData("full_application", 17, $general);
if($processor->getConn()){
    list($general, $phones) = $processor->processGeneralInfo($_REQUEST['general_information']);
    print $processor->insertData("full_application", 17, $general);
}
 public function insertData($table, $qty, $data){                                                                
    $errors = "";                                                                                            
    $columns = $this->fetchColumnNames($table);                                                              
    $column_list = implode(', ', $columns);                                                                  
    $values = array_fill(0, $qty, '?');                                                                           
    $value_list = implode(', ', $values);                                                                         
    $q = "INSERT INTO $table ($column_list) VALUES ($value_list)";                                                
    $stmt = $this->conn->prepare($q);                                                                             
    for($i = 1; $i < $qty + 1; $i++){                                                                             
        foreach($data as $key => $val){                                                                           
            if($key == $columns[$i-1]){                                                                           
                try{                                                                                              
                    if(is_numeric($val)){                                                                         
                        $stmt->bindValue($i, $val, PDO::PARAM_INT);                                              
                    }else{                                                                                        
                        $stmt->bindValue($i, $val, PDO::PARAM_STR);                                               
                    }                                                                                             
                }catch(PDOException $e){                                                                          
                    print  $e->getMessage();                                                                      
                }                                                                                                 
            }                                                                                                     
        }                                                                                                         
    }                                                                                                             
    try{                                                                                                          
        $stmt->execute();                                                                                         
    }catch(PDOException $e){                                                                                      
        $errors .=  $e->getMessage();                                                                             
        print $errors;                                                                                            
    }                                                                                                             

}

public function getApplicationid(){
    $query = "SELECT id FROM eagle.full_application ORDER BY create_date DESC LIMIT 1";
    $id = null;
    foreach($this->conn->query($query) as $row){
        $id = $row['id'];
    }
    return $id;
}
error_reporting(E_ALL);
ini_set('display_errors', 1);
include '../../inc/config.php';
include 'ProcessApplication/ProcessApplication.php';
include 'ProcessApplication/ProcessApplicationQuery.php';
$processor = new ProcessApplicationQuery($CONN);
$processor->insertData("full_application", 17, $general);
if($processor->getConn()){
    list($general, $phones) = $processor->processGeneralInfo($_REQUEST['general_information']);
    $processor->insertData("full_application", 17, $general);
    echo $processor->getApplicationId();
}