Précédent   Forum des professionnels en informatique > Bases de données > MS SQL-Server
MS SQL-Server Forum Microsoft SQL-Server. Avant de poster -> FAQ SQL-Server, Tutoriels SQL-Server
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 08/02/2011, 12h27   #1
Invité de passage
 
Inscription : décembre 2003
Messages : 20
Détails du profil
Informations forums :
Inscription : décembre 2003
Messages : 20
Points : 0
Points : 0
Par défaut SQL Server retourne des champs vides

Bonjour,

En voulant afficher des champs en PHP, j'ai un symptôme que j'ai déjà remarqué auparavant en ASP:
Je fais un select * sur une table. si je n'accède pas aux champs dans l'ordre où ils sont retournés, certains champs on une valeur vide, alors que le champ a bien une valeur dans la base.
Le problème n’apparaît pas avec MySQL.

Qqu connais-t'il ce problème?

--Cédric
Ferllings est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/02/2011, 13h17   #2
Membre Expert
 
Inscription : janvier 2010
Messages : 1 084
Détails du profil
Informations personnelles :
Localisation : France, Rhône (Rhône Alpes)

Informations forums :
Inscription : janvier 2010
Messages : 1 084
Points : 1 573
Points : 1 573
Bonjour,

Pour ma part, je n'ai jamais rencontré ce problème...

PHP tourne sous windows ou linux ?
Comment accèdes-tu à tes données ?

Est-ce que ça te fais la même chose si au lieu d'un select *, tu nommes tes colonnes :
SELECT colonne1, Colonne2, ...
(ce qui par ailleurs serait une bonne chose...)
aieeeuuuuu est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/02/2011, 14h01   #3
Invité de passage
 
Inscription : décembre 2003
Messages : 20
Détails du profil
Informations forums :
Inscription : décembre 2003
Messages : 20
Points : 0
Points : 0
Je viens de faire un petit essai en ASP:
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
 
<h2>Test 1</h2>
 
    <%
	id=1
 
	SQL_query = "SELECT * FROM " & TABLE _
		& " WHERE id = " & id 
	SET RS = MyConn.Execute(SQL_query)
	IF (NOT RS.eof) Then
		applicant_name = RS("applicant_name")
		applicant_address = RS("applicant_address")
		applicant_phone = RS("applicant_phone")
		applicant_mobile = RS("applicant_mobile")
		applicant_fax = RS("applicant_fax")
		applicant_website = RS("applicant_website")
		applicant_email = RS("applicant_email")
	End IF
	RS.close
	SET RS = nothing
 
%>
<p><%=applicant_name%></p>
<p><%=applicant_address%></p>
<p><%=applicant_phone%></p>
<p><%=applicant_mobile%></p>
<p><%=applicant_fax%></p>
<p><%=applicant_website%></p>
<p><%=applicant_email%></p>
 
<h2>Test 2</h2>
 
    <%
 
	SQL_query = "SELECT * FROM " & TABLE _
		& " WHERE id = " & id 
	SET RS = MyConn.Execute(SQL_query)
	IF (NOT RS.eof) Then
		applicant_website = RS("applicant_website")
		applicant_fax = RS("applicant_fax")
		applicant_phone = RS("applicant_phone")
		applicant_address = RS("applicant_address")
		applicant_mobile = RS("applicant_mobile")
		applicant_email = RS("applicant_email")
		applicant_name = RS("applicant_name")
	End IF
	RS.close
	SET RS = nothing
 
%>
<p><%=applicant_name%></p>
<p><%=applicant_address%></p>
<p><%=applicant_phone%></p>
<p><%=applicant_mobile%></p>
<p><%=applicant_fax%></p>
<p><%=applicant_website%></p>
<p><%=applicant_email%></p>
 
<h2>Test 3</h2>
 
    <%
 
	SQL_query = "SELECT applicant_website, applicant_fax, applicant_phone, applicant_address, applicant_mobile, applicant_email, applicant_name FROM " & TABLE _
		& " WHERE id = " & id 
	SET RS = MyConn.Execute(SQL_query)
	IF (NOT RS.eof) Then
		applicant_website = RS("applicant_website")
		applicant_fax = RS("applicant_fax")
		applicant_phone = RS("applicant_phone")
		applicant_address = RS("applicant_address")
		applicant_mobile = RS("applicant_mobile")
		applicant_email = RS("applicant_email")
		applicant_name = RS("applicant_name")
	End IF
	RS.close
	SET RS = nothing
 
%>
<p><%=applicant_name%></p>
<p><%=applicant_address%></p>
<p><%=applicant_phone%></p>
<p><%=applicant_mobile%></p>
<p><%=applicant_fax%></p>
<p><%=applicant_website%></p>
<p><%=applicant_email%></p>
Ce qui affiche (les valeurs sont identiques aux noms des champs)
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 
Test 1
applicant_name
applicant_address
applicant_phone
applicant_mobile
applicant_fax
applicant_website
example@example.com
 
Test 2
applicant_name
applicant_website
example@example.com
 
Test 3
applicant_name
applicant_address
applicant_phone
applicant_mobile
applicant_fax
applicant_website
example@example.com
Effectivement, en remplacant * par le nom des champs, ca fonctionne.
Le problème c'est que j'utilise un framework php (yii) qui gère ca tout seul.
Ferllings est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/02/2011, 14h16   #4
Membre Expert
 
Inscription : janvier 2010
Messages : 1 084
Détails du profil
Informations personnelles :
Localisation : France, Rhône (Rhône Alpes)

Informations forums :
Inscription : janvier 2010
Messages : 1 084
Points : 1 573
Points : 1 573
Citation:
Envoyé par Ferllings Voir le message
Effectivement, en remplacant * par le nom des champs, ca fonctionne.
Le problème c'est que j'utilise un framework php (yii) qui gère ca tout seul.
Alors comme workaround, tu peux peut etre essayer de faire un foreach sur toutes les colonnes de ton RS avant d'acceder aux colonnes par leur nom...

C'est pas très propre, mais bon... c'est pas pire qu'un SELECT *
aieeeuuuuu est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 07h53.


 
 
 
 
Partenaires

Hébergement Web