IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

PHP & Base de données Discussion :

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000 [MySQL]


Sujet :

PHP & Base de données

  1. #1
    Membre éprouvé
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juillet 2006
    Messages
    985
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Cameroun

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Juillet 2006
    Messages : 985
    Par défaut Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000
    Bonjour,
    J'ai ce array :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
     
    $myArray = array (
        0 => array (
    		  'structure_id' => '160',
    		  'structure_libelle' => 'Cabinet',
    		  'structure_level' => '-1',
    		  'structure_login' => '16-1-160-1',
    		  'structure_pswd1' => 'iv0ih0e0',
    		  'sub' => NULL,
    		),
        1 => array (
    		  'structure_id' => '161',
    		  'structure_libelle' => 'Inspection Générale de l’Evaluation des Performances des Services',
    		  'structure_level' => '-1',
    		  'structure_login' => '16-1-161-1',
    		  'structure_pswd1' => '01fadaex',
    		  'sub' => array (
    						0 => array (
    								'structure_id' => '1',
    								'structure_libelle' => 'Délégation Départementale - Djérem',
    								'structure_level' => '2',
    								'structure_login' => '16-2-1-2',
    								'structure_pswd1' => 'wdhafmq5',
    								'sub' => NULL
    							),
    						1 => array (
    								'structure_id' => '1',
    								'structure_libelle' => 'Délégation Départementale - Djérem',
    								'structure_level' => '2',
    								'structure_login' => '16-2-1-2',
    								'structure_pswd1' => 'wdhafmq5',
    								'sub' => array (
    											0 => array (
    													'structure_id' => '1',
    													'structure_libelle' => 'Délégation Départementale - Djérem',
    													'structure_level' => '2',
    													'structure_login' => '16-2-1-2',
    													'structure_pswd1' => 'wdhafmq5',
    													'sub' => NULL
    												)
    										)
    							)
    					)
    		),
        2 => array (
    		  'structure_id' => '162',
    		  'structure_libelle' => 'Inspection Générale de l’Evaluation du Fonctionnement des Services',
    		  'structure_level' => '-1',
    		  'structure_login' => '16-1-162-1',
    		  'structure_pswd1' => '8kyalmle',
    		  'sub' => NULL,
    		)
    );
    Je le parcours ainsi pour faire des insertions dans ma bdd
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    function remplir_dbb($array) {
    	foreach ($array as $data) {
    		foreach ($data as $value) {
    			insertValidateur($value);
    			if ( isset($value['sub']) && is_array($value['sub']) ) {
    				remplir_dbb($value['sub']);
    			}
    		}
    	}
    }
     
    remplir_dbb($myArray);
    Message d'erreur :
    ( ! ) Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'login' cannot be null' in I:\wamp2\www\validation\index.php on line 285
    ( ! ) PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'login' cannot be null in I:\wamp2\www\validation\index.php on line 285
    D'où pourrait provenir cette erreur ?
    [EDIT]
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    function insertValidateur($array) {
    	global $db;
    	$return = false;
    	$sql = 'INSERT INTO validateurs (login, pswd, salt) VALUES (:login, :pswd, :salt)';
    	$statement = $db->prepare($sql);
    	if ( $statement->execute(array(':login' => $array['structure_login'], ':pswd' => $array['structure_pswd'], ':salt' => $array['structure_salt'])) ) { $return = true;}
    	return $return;
    }
    Merci d'avance...

  2. #2
    Expert confirmé

    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    7 920
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 7 920
    Par défaut
    fait un

  3. #3
    Membre éprouvé
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juillet 2006
    Messages
    985
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Cameroun

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Juillet 2006
    Messages : 985
    Par défaut
    Citation Envoyé par stealth35 Voir le message
    fait un
    array
    0 =>
    array
    'structure_id' => string '160' (length=3)
    'structure_libelle' => string 'Cabinet' (length=7)
    'structure_level' => string '-1' (length=2)
    'structure_login' => string '16-1-160-1' (length=10)
    'structure_pswd1' => string 'iv0ih0e0' (length=8)
    'sub' => null
    1 =>
    array
    'structure_id' => string '161' (length=3)
    'structure_libelle' => string 'Inspection Générale de l’Evaluation des Performances des Services' (length=69)
    'structure_level' => string '-1' (length=2)
    'structure_login' => string '16-1-161-1' (length=10)
    'structure_pswd1' => string '01fadaex' (length=8)
    'sub' =>
    array
    0 =>
    array
    ...
    1 =>
    array
    ...
    2 =>
    array
    'structure_id' => string '162' (length=3)
    'structure_libelle' => string 'Inspection Générale de l’Evaluation du Fonctionnement des Services' (length=70)
    'structure_level' => string '-1' (length=2)
    'structure_login' => string '16-1-162-1' (length=10)
    'structure_pswd1' => string '8kyalmle' (length=8)
    'sub' => null
    Voilà le résultat

  4. #4
    Expert confirmé

    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    7 920
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 7 920
    Par défaut
    le $array de insertValidateur

  5. #5
    Membre éprouvé
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juillet 2006
    Messages
    985
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Cameroun

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Juillet 2006
    Messages : 985
    Par défaut
    Citation Envoyé par stealth35 Voir le message
    le $array de insertValidateur
    insertValidateur($array) recoit bien un array qui possède bien les propriété structure_login, structure_pswd, structure_salt.

    franchement je ne comprends pas le problème.

  6. #6
    Expert confirmé

    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    7 920
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 7 920
    Par défaut
    Citation Envoyé par okoweb Voir le message
    insertValidateur($array) recoit bien un array qui possède bien les propriété structure_login, structure_pswd, structure_salt.

    franchement je ne comprends pas le problème.
    bah montre

  7. #7
    Membre éprouvé
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juillet 2006
    Messages
    985
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Cameroun

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Juillet 2006
    Messages : 985
    Par défaut
    Citation Envoyé par stealth35 Voir le message
    bah montre
    SVP qu'est-ce je montre ? Ci haut, il y'a tout le code.

    Merci pour votre aide.

  8. #8
    Expert confirmé

    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    7 920
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 7 920
    Par défaut
    Citation Envoyé par okoweb Voir le message
    SVP qu'est-ce je montre ? Ci haut, il y'a tout le code.

    Merci pour votre aide.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    function insertValidateur($array) {
    	global $db;
            var_dump($array);
    	$return = false;
    	$sql = 'INSERT INTO validateurs (login, pswd, salt) VALUES (:login, :pswd, :salt)';
    	$statement = $db->prepare($sql);
    	if ( $statement->execute(array(':login' => $array['structure_login'], ':pswd' => $array['structure_pswd'], ':salt' => $array['structure_salt'])) ) { $return = true;}
    	return $return;
    }

  9. #9
    Membre éprouvé
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juillet 2006
    Messages
    985
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Cameroun

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Juillet 2006
    Messages : 985
    Par défaut
    J'ai modifié mes fonctions ainsi
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
     
    function insertValidateur($login, $pswd, $salt) {
    	global $db;
    	$return = false;
    	$sql = 'INSERT INTO validateurs (login, pswd, salt) VALUES (:login, :pswd, :salt)';
    	$statement = $db->prepare($sql);
    	if ( $statement->execute(array(':login' => $login, ':pswd' => $pswd, ':salt' => $salt)) ) { $return = true; }
    	return $return;
    }
     
    function remplir_dbb($array) {
    	foreach ($array as $data) {
    		//var_dump($data);
    		insertValidateur($data['structure_login'], $data['structure_pswd1'], $data['structure_libelle']);
    		if ( isset($data['sub']) && is_array($data['sub']) ) {
    			remplir_dbb($data['sub']);
    		}
    	}
    }
     
    $myArray = array (
        0 => array (
    		  'structure_id' => '160',
    		  'structure_libelle' => 'Cabinet',
    		  'structure_level' => '-1',
    		  'structure_login' => '16-1-160-1',
    		  'structure_pswd1' => 'iv0ih0e0',
    		  'sub' => NULL,
    		),
        1 => array (
    		  'structure_id' => '161',
    		  'structure_libelle' => 'Inspection Générale de l’Evaluation des Performances des Services',
    		  'structure_level' => '-1',
    		  'structure_login' => '16-1-161-1',
    		  'structure_pswd1' => '01fadaex',
    		  'sub' => array (
    						0 => array (
    								'structure_id' => '1',
    								'structure_libelle' => 'Délégation Départementale - Djérem',
    								'structure_level' => '2',
    								'structure_login' => '16-2-1-2',
    								'structure_pswd1' => 'wdhafmq5',
    								'sub' => NULL
    							),
    						1 => array (
    								'structure_id' => '1',
    								'structure_libelle' => 'Délégation Départementale - Djérem',
    								'structure_level' => '2',
    								'structure_login' => '16-2-1-2',
    								'structure_pswd1' => 'wdhafmq5',
    								'sub' => array (
    											0 => array (
    													'structure_id' => '1',
    													'structure_libelle' => 'Délégation Départementale - Djérem',
    													'structure_level' => '2',
    													'structure_login' => '16-2-1-2',
    													'structure_pswd1' => 'wdhafmq5',
    													'sub' => NULL
    												)
    										)
    							)
    					)
    		),
        2 => array (
    		  'structure_id' => '162',
    		  'structure_libelle' => 'Inspection Générale de l’Evaluation du Fonctionnement des Services',
    		  'structure_level' => '-1',
    		  'structure_login' => '16-1-162-1',
    		  'structure_pswd1' => '8kyalmle',
    		  'sub' => NULL,
    		)
    );
     
    remplir_dbb($myArray);
    Ça marche super bien

  10. #10
    Membre éprouvé
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juillet 2006
    Messages
    985
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Cameroun

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Juillet 2006
    Messages : 985
    Par défaut Quelles différences entre ces 2 array ?
    Avec ce array, j'ai ces erreurs
    Notice: Undefined index: structure_login in I:\wamp2\www\validation\index.php on line 326
    Notice: Undefined index: structure_pswd1 in I:\wamp2\www\validation\index.php on line 326
    Notice: Undefined index: structure_libelle in I:\wamp2\www\validation\index.php on line 326

    ( ! ) Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'login' cannot be null' in I:\wamp2\www\validation\index.php on line 286
    ( ! ) PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'login' cannot be null in I:\wamp2\www\validation\index.php on line 286
    Quelle différence sur les 2 array ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
     
    Array
    (
        [1] => Array
            (
                [0] => Array
                    (
                        [structure_id] => 120
                        [structure_libelle] => Cabinet
                        [structure_level] => -1
                        [structure_login] => 4-1-120-1
                        [structure_pswd1] => l5arehh7
                        [structure_pswd] => 17d6ebe8f8d8fd4760639852bb69588c56d326a3
                        [structure_salt] => PUA20/R
                        [sub] => 
                    )
     
                [1] => Array
                    (
                        [structure_id] => 121
                        [structure_libelle] => Inspection Générale
                        [structure_level] => -1
                        [structure_login] => 4-1-121-1
                        [structure_pswd1] => yeuvkahj
                        [structure_pswd] => 15cfee4321ed5df61d6dbd00d15012ba297e1b8c
                        [structure_salt] => GUY-?,
                        [sub] => 
                    )
     
                [2] => Array
                    (
                        [structure_id] => 122
                        [structure_libelle] => Secrétariat Général
                        [structure_level] => -1
                        [structure_login] => 4-1-122-1
                        [structure_pswd1] => wyyuu9jt
                        [structure_pswd] => 5ffedfe75f375105c07dc9e7be3ed65c846a2f16
                        [structure_salt] => _@E6>.A
                        [sub] => 
                    )
     
                [3] => Array
                    (
                        [structure_id] => 123
                        [structure_libelle] => Chef de Division des Affaires Juridiques
                        [structure_level] => -1
                        [structure_login] => 4-1-123-1
                        [structure_pswd1] => qub634bo
                        [structure_pswd] => b327a6ee17a1573d01bb1e1f475ea114b1b51fe7
                        [structure_salt] => @WUG131Q
                        [sub] => 
                    )
     
                [4] => Array
                    (
                        [structure_id] => 124
                        [structure_libelle] => Direction des Ressources Humaines
                        [structure_level] => -1
                        [structure_login] => 4-1-124-1
                        [structure_pswd1] => wcgelcrd
                        [structure_pswd] => 24c3348cf2cd1bc8be36efec51dc5a6dee8b5f87
                        [structure_salt] => VH"k/C
                        [sub] => 
                    )
     
                [5] => Array
                    (
                        [structure_id] => 125
                        [structure_libelle] => Direction des Enquêtes et des Statistiques Agricoles
                        [structure_level] => -1
                        [structure_login] => 4-1-125-1
                        [structure_pswd1] => onho4sx8
                        [structure_pswd] => c268e6701da0504bcca69d924633d2ec9930982d
                        [structure_salt] => K
    V!35E
                        [sub] => 
                    )
     
                [6] => Array
                    (
                        [structure_id] => 126
                        [structure_libelle] => Direction du Développement de l’Agriculture
                        [structure_level] => -1
                        [structure_login] => 4-1-126-1
                        [structure_pswd1] => xruphopm
                        [structure_pswd] => 528581675ef69fd94d61b0d0dae51ec882fb8bd7
                        [structure_salt] => RA-`tX
                        [sub] => 
                    )
     
                [7] => Array
                    (
                        [structure_id] => 127
                        [structure_libelle] => Direction des organisations Professionnelles Agricoles et de l’Appui aux Exploitations Agricoles
                        [structure_level] => -1
                        [structure_login] => 4-1-127-1
                        [structure_pswd1] => w24ba1ml
                        [structure_pswd] => 9ed636da2d49f02bcb5ddfd22c32ec2222420d1e
                        [structure_salt] => ^JWJ-`%D
                        [sub] => 
                    )
     
                [8] => Array
                    (
                        [structure_id] => 128
                        [structure_libelle] => Direction de la Réglementation et du Contrôle de Qualité des Intrants et des Produits Agricoles
                        [structure_level] => -1
                        [structure_login] => 4-1-128-1
                        [structure_pswd1] => v7pftqir
                        [structure_pswd] => f749ab8076accce023d0daf8e2fc7d57a674786b
                        [structure_salt] => VIre4Q
                        [sub] => 
                    )
     
                [9] => Array
                    (
                        [structure_id] => 129
                        [structure_libelle] => Direction du Génie Rural et de l’Amélioration du Cadre de Vie en Milieu Rural
                        [structure_level] => -1
                        [structure_login] => 4-1-129-1
                        [structure_pswd1] => zsmko19t
                        [structure_pswd] => 19bd09546ae16d352a665d02448d54975f0ed315
                        [structure_salt] => WUBZP.?w
                        [sub] => 
                    )
     
                [10] => Array
                    (
                        [structure_id] => 130
                        [structure_libelle] => Direction du Développement Local et Communautaire
                        [structure_level] => -1
                        [structure_login] => 4-1-130-1
                        [structure_pswd1] => 056tiipj
                        [structure_pswd] => 5ab7266b39f46b06e6126bd677de87112253fcad
                        [structure_salt] => JX[
    Dr4>U
                        [sub] => 
                    )
     
    )

  11. #11
    Membre éprouvé
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juillet 2006
    Messages
    985
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Cameroun

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Juillet 2006
    Messages : 985
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
     
    function remplir_dbb($array) {
    	foreach ($array as $datas) {
    		//var_dump($datas);
    		foreach ($datas as $data) {
    			//echo $data['structure_login']. ' - ' .$data['structure_pswd1']. ' - ' .$data['structure_libelle']. ' - ' .$data['sub']. '<br />';
    			insertValidateur($data['structure_login'], $data['structure_pswd1'], $data['structure_libelle']);
    			if ( isset($data['sub']) && is_array($data['sub']) ) {
    				//remplir_dbb($data['sub']);
    				foreach ($data['sub'] as $sub) {
    					//echo $sub['structure_login']. ' - ' .$sub['structure_pswd1']. ' - ' .$sub['structure_libelle']. ' - ' .$sub['sub']. '<br />';
    					insertValidateur($sub['structure_login'], $sub['structure_pswd1'], $sub['structure_libelle']);
    					if ( isset($sub['sub']) && is_array($sub['sub']) ) {
    						foreach ($sub['sub'] as $sub2) {
    							//echo $sub2['structure_login']. ' - ' .$sub2['structure_pswd1']. ' - ' .$sub2['structure_libelle']. ' - ' .$sub2['sub']. '<br />';
    							insertValidateur($sub2['structure_login'], $sub2['structure_pswd1'], $sub2['structure_libelle']);
    						}
    					}
    				}
     
    			}
    		}
    	}
    }
    J'ai modifié ma fonction ainsi. Mais je pense, de manière propre, une fonction récursive ferait affaire pour gérer la profondeur. Je n'ai pas pu rendre cette fonction récursive.
    Le problème est résolu, mais je reste ouvert pour la fonction récursive.

    Merci.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 2
    Dernier message: 08/04/2015, 20h59
  2. Réponses: 2
    Dernier message: 30/03/2015, 11h18
  3. Réponses: 1
    Dernier message: 07/08/2012, 23h48
  4. [MySQL] Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002]
    Par -Fly- dans le forum PHP & Base de données
    Réponses: 2
    Dernier message: 11/04/2011, 11h18
  5. Réponses: 3
    Dernier message: 04/04/2011, 17h32

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo