Précédent   Forum des professionnels en informatique > PHP > PHP & SGBD > PHP & MySQL
PHP & MySQL Forum d'entraide sur les fonctions MySQL avec PHP. Avant de poster -> FAQ MySQL, Cours MySQL et Sources MySQL. Pour les questions concernant le moteur MySQL plutôt que les fonctions PHP, merci d'utiliser le forum MySQL.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 30/11/2011, 13h50   #1
Membre éclairé
 
Homme Gérard Okono
Développeur Web
Inscription : juillet 2006
Messages : 711
Détails du profil
Informations personnelles :
Nom : Homme Gérard Okono
Localisation : Cameroun

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

Informations forums :
Inscription : juillet 2006
Messages : 711
Points : 328
Points : 328
Par défaut Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000

Bonjour,
J'ai ce array :
Code :
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 :
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 :
Citation:
( ! ) 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 :
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...
okoweb est déconnecté   Envoyer un message privé Réponse avec citation 01
Vieux 30/11/2011, 13h55   #2
Modérateur
 
Inscription : septembre 2010
Messages : 7 219
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 219
Points : 8 598
Points : 8 598
fait un
__________________
http://blog.stealth35.com/
stealth35 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/11/2011, 13h59   #3
Membre éclairé
 
Homme Gérard Okono
Développeur Web
Inscription : juillet 2006
Messages : 711
Détails du profil
Informations personnelles :
Nom : Homme Gérard Okono
Localisation : Cameroun

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

Informations forums :
Inscription : juillet 2006
Messages : 711
Points : 328
Points : 328
Citation:
Envoyé par stealth35 Voir le message
fait un
Citation:
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
okoweb est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/11/2011, 14h01   #4
Modérateur
 
Inscription : septembre 2010
Messages : 7 219
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 219
Points : 8 598
Points : 8 598
le $array de insertValidateur
__________________
http://blog.stealth35.com/
stealth35 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/11/2011, 14h08   #5
Membre éclairé
 
Homme Gérard Okono
Développeur Web
Inscription : juillet 2006
Messages : 711
Détails du profil
Informations personnelles :
Nom : Homme Gérard Okono
Localisation : Cameroun

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

Informations forums :
Inscription : juillet 2006
Messages : 711
Points : 328
Points : 328
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.
okoweb est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/11/2011, 14h22   #6
Modérateur
 
Inscription : septembre 2010
Messages : 7 219
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 219
Points : 8 598
Points : 8 598
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
__________________
http://blog.stealth35.com/
stealth35 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/11/2011, 14h43   #7
Membre éclairé
 
Homme Gérard Okono
Développeur Web
Inscription : juillet 2006
Messages : 711
Détails du profil
Informations personnelles :
Nom : Homme Gérard Okono
Localisation : Cameroun

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

Informations forums :
Inscription : juillet 2006
Messages : 711
Points : 328
Points : 328
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.
okoweb est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/11/2011, 14h49   #8
Modérateur
 
Inscription : septembre 2010
Messages : 7 219
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 219
Points : 8 598
Points : 8 598
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 :
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;
}
__________________
http://blog.stealth35.com/
stealth35 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 01/12/2011, 10h42   #9
Membre éclairé
 
Homme Gérard Okono
Développeur Web
Inscription : juillet 2006
Messages : 711
Détails du profil
Informations personnelles :
Nom : Homme Gérard Okono
Localisation : Cameroun

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

Informations forums :
Inscription : juillet 2006
Messages : 711
Points : 328
Points : 328
J'ai modifié mes fonctions ainsi
Code :
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
okoweb est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 01/12/2011, 11h03   #10
Membre éclairé
 
Homme Gérard Okono
Développeur Web
Inscription : juillet 2006
Messages : 711
Détails du profil
Informations personnelles :
Nom : Homme Gérard Okono
Localisation : Cameroun

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

Informations forums :
Inscription : juillet 2006
Messages : 711
Points : 328
Points : 328
Par défaut Quelles différences entre ces 2 array ?

Avec ce array, j'ai ces erreurs
Citation:
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 :
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] => 
                )
 
)
okoweb est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/12/2011, 08h32   #11
Membre éclairé
 
Homme Gérard Okono
Développeur Web
Inscription : juillet 2006
Messages : 711
Détails du profil
Informations personnelles :
Nom : Homme Gérard Okono
Localisation : Cameroun

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

Informations forums :
Inscription : juillet 2006
Messages : 711
Points : 328
Points : 328
Code :
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.
okoweb est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 00h46.


 
 
 
 
Partenaires

Hébergement Web