Précédent   Forum des professionnels en informatique > PHP > PHP & SGBD > PDO
PDO Forum d'entraide sur PDO (PHP Data Objects) : pilote générique de bases de données avec PHP. Avant de poster -> FAQ PDO et Cours PDO
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 26/10/2011, 17h28   #1
Invité régulier
 
Inscription : avril 2011
Messages : 60
Détails du profil
Informations forums :
Inscription : avril 2011
Messages : 60
Points : 9
Points : 9
Par défaut requête PDO et LIKE

Bonjour a tous,
Je n'arrive pas a résoudre mon soucis avec LIKE et PDO.

message d'erreur : Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 83 bytes)

code concerné :

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
 
$offre = $connexion -> prepare("SELECT id_offre, departement, poste, date, experience, salaire, id_user FROM offres WHERE experience LIKE :motclef ORDER BY date DESC");
		$listoffres = array();
		while($offre -> execute(array('motclef' => '%'.$requete.'%' )))
			{
 
  		 	$liste_offres['id_offre'];
 
  			// Nom du poste
  			$poste = $connexion -> prepare("SELECT poste FROM postes WHERE id_poste=:id");
			$poste -> BindValue('id',$liste_offres['poste']);
			$poste -> execute();
			$nom_poste  =  $poste->fetch();
  			$liste_offres['poste'] = $nom_poste['poste'];
 
  			$liste_offres['date'] = date('d/m/Y',strtotime(''.$liste_offres['date'].' 00:00'));
 
  			// Nom du département
  			$departement = $connexion -> prepare("SELECT nom FROM dept WHERE id_dept=:id_dept");
			$departement -> BindValue('id_dept',$liste_offres['departement']);
			$departement -> execute();
			$nom_departement  =  $departement->fetch();
 
  			$liste_offres['departement'] = $nom_departement['nom'];
  			$listoffres[] = $liste_offres;
			}
le nOoB est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/10/2011, 17h31   #2
Modérateur
 
Inscription : septembre 2010
Messages : 7 131
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 131
Points : 8 491
Points : 8 491
a quoi sert ton while ?
__________________
http://blog.stealth35.com/
stealth35 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/10/2011, 17h33   #3
Invité régulier
 
Inscription : avril 2011
Messages : 60
Détails du profil
Informations forums :
Inscription : avril 2011
Messages : 60
Points : 9
Points : 9
Pour récupérer tous les champs qui contiennent le contenue de la recherche.
le nOoB est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/10/2011, 17h37   #4
Modérateur
 
Inscription : septembre 2010
Messages : 7 131
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 131
Points : 8 491
Points : 8 491
Citation:
Envoyé par le nOoB Voir le message
Pour récupérer tous les champs qui contiennent le contenue de la recherche.
non la tu execute la requête la l'infinie, relis toi bien
__________________
http://blog.stealth35.com/
stealth35 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/10/2011, 17h49   #5
Invité régulier
 
Inscription : avril 2011
Messages : 60
Détails du profil
Informations forums :
Inscription : avril 2011
Messages : 60
Points : 9
Points : 9
exact

j'ais modifié mais comme c'est la première fois que j'utilise like avec pdo je sais pas trop comment faire et sur le web ou dans mes bouquins je trouve pas grand chose. Je pense que sa vient du faite que je fasse deux tableaux ....

nouveau message d'erreur : Fatal error: Call to a member function fetch() on a non-object

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
 
$offre = $connexion -> prepare("SELECT id_offre, departement, poste, date, experience, salaire, id_user FROM offres WHERE experience LIKE :motclef ORDER BY date DESC");
		$offre -> execute(array('motclef' => '%'.$requete.'%' ));
		$listoffres = array();
		while($liste_offres -> fetch())
			{
 
  		 	$liste_offres['id_offre'];
 
  			// Nom du poste
  			$poste = $connexion -> prepare("SELECT poste FROM postes WHERE id_poste=:id");
			$poste -> BindValue('id',$liste_offres['poste']);
			$poste -> execute();
			$nom_poste  =  $poste->fetch();
  			$liste_offres['poste'] = $nom_poste['poste'];
 
  			$liste_offres['date'] = date('d/m/Y',strtotime(''.$liste_offres['date'].' 00:00'));
 
  			// Nom du département
  			$departement = $connexion -> prepare("SELECT nom FROM dept WHERE id_dept=:id_dept");
			$departement -> BindValue('id_dept',$liste_offres['departement']);
			$departement -> execute();
			$nom_departement  =  $departement->fetch();
 
  			$liste_offres['departement'] = $nom_departement['nom'];
  			$listoffres[] = $liste_offres;
			}
le nOoB est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/10/2011, 17h55   #6
Modérateur
 
Inscription : septembre 2010
Messages : 7 131
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 131
Points : 8 491
Points : 8 491
tu te relis pas ...

t'as $listoffres et après $liste_offres, et pareil ton while ne sert pas a grand chose ici, est ce que tu comprends comment fonctionne un while ?
__________________
http://blog.stealth35.com/
stealth35 est déconnecté   Envoyer un message privé Réponse avec citation 10
Vieux 26/10/2011, 17h56   #7
Invité régulier
 
Inscription : avril 2011
Messages : 60
Détails du profil
Informations forums :
Inscription : avril 2011
Messages : 60
Points : 9
Points : 9
correction

erreur : Parse error: syntax error, unexpected T_STRING in

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
 
$offre = $connexion -> prepare("SELECT id_offre, departement, poste, date, experience, salaire, id_user FROM offres WHERE experience LIKE :motclef ORDER BY date DESC");
		$offre -> execute(array('motclef' => '%'.$requete.'%' ));
		$listoffres = array();
		while($liste_offres -> fetch())
			{
 
  		 	$liste_offres['id_offre'];
 
  			// Nom du poste
  			$poste = $connexion -> prepare("SELECT poste FROM postes WHERE id_poste=:id");
			$poste -> BindValue('id',$liste_offres['poste']);
			$poste -> execute();
			$nom_poste  =  $poste->fetch();
  			$liste_offres['poste'] = $nom_poste['poste'];
 
  			$liste_offres['date'] = date('d/m/Y',strtotime(''.$liste_offres['date'].' 00:00'));
 
  			// Nom du département
  			$departement = $connexion -> prepare("SELECT nom FROM dept WHERE id_dept=:id_dept");
			$departement -> BindValue('id_dept',$liste_offres['departement']);
			$departement -> execute();
			$nom_departement  =  $departement->fetch();
 
  			$liste_offres['departement'] = $nom_departement['nom'];
  			$listoffres[] = $liste_offres;
			}
le nOoB est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/10/2011, 17h58   #8
Modérateur
 
Inscription : septembre 2010
Messages : 7 131
Détails du profil
Informations forums :
Inscription : septembre 2010
Messages : 7 131
Points : 8 491
Points : 8 491
...
__________________
http://blog.stealth35.com/
stealth35 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/10/2011, 09h17   #9
Invité régulier
 
Inscription : avril 2011
Messages : 60
Détails du profil
Informations forums :
Inscription : avril 2011
Messages : 60
Points : 9
Points : 9
je poste la version corrigée.

Code :
1
2
3
4
5
 
$offre = $connexion -> prepare("SELECT id_offre, departement, poste, date, experience, salaire, id_user FROM offres WHERE experience LIKE :motclef ORDER BY date DESC LIMIT ".$page_calc.",".$nb_affichage."");
		$offre -> execute(array('motclef' => '%'.$requete.'%' ));
		$listoffres = array();
		while($liste_offres = $offre -> fetch())
Par contre avec un select count j'ais pas de message d'érreur mais plus rien ne s'affiche.

Code :
1
2
3
4
 
$offremotclef = $connexion -> prepare("SELECT count(*) AS id_offre FROM offres WHERE valide=1 AND experience LIKE :motclef ");
		$offremotclef -> execute(array('motclef' => '%'.$requete.'%' ));
		$retour_motclef = $offremotclef ->fetchColumn();
le nOoB est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/10/2011, 09h27   #10
Invité régulier
 
Inscription : avril 2011
Messages : 60
Détails du profil
Informations forums :
Inscription : avril 2011
Messages : 60
Points : 9
Points : 9
voila j'ais trouvé sa venait du dysplay du moteur de template qui était perdu au milieu de la page avant les requête donc normal que sa n'affichait plus rien
le nOoB 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 08h59.


 
 
 
 
Partenaires

Hébergement Web