sql >> Base de Datos >  >> RDS >> Mysql

No se puede insertar la matriz en la base de datos

Está intentando insertar una matriz dentro de for insertStudentData[key] .

Prueba esto:

 $insertStudentData[$key] = array(
        'parent_id'      => $parent_id,
        'email'          => $studentDatas['email'],
        'password'       => $studentDatas['password'],
        'name'           => $studentDatas['name'],
        'nric'           => $studentDatas['nric'],
        'gender'         => $studentDatas['gender'],
        'photo'          => $studentDatas['photo'],
        'is_active'      => $studentDatas['is_active']['0']['photo'],
    );

$this->db->insert('users_student', $insertStudentData[$key]);

si intenta insertar varias filas, puede usar insertar_lote

He probado tu código de mi lado y se vuelve perfectamente correcto. agregó las filas múltiples a la tabla. Esto es lo que he hecho.

function create($studentData){
$insertStudentData = ''; //Create a Variable
    foreach ($studentData => $studentDatas) {

        $insertStudentData[] = array(
            'parent_id'      => $parent_id,
            'email'          => $studentDatas['email'],
            'password'       => $studentDatas['password'],
            'name'           => $studentDatas['name'],
            'nric'           => $studentDatas['nric'],
            'gender'         => $studentDatas['gender'],
            'photo'          => $studentDatas['photo']['0']['photo'],
            'is_active'      => $studentDatas['is_active']
        );

    }

    $this->db->insert_batch('users_student', $insertStudentData[$key]);

    if($this->db->affected_rows() != 1){
        return false;
    } else {
        return true;
    }
}