environnement :
MySQL :
Serveur: localhost via TCP/IP
Version du serveur: 5.1.30-community
Version du protocole: 10
Utilisateur: root@localhost
Jeu de caractères pour MySQL: UTF-8 Unicode (utf8)
Serveur web :
Apache/2.2.11 (Win32) PHP/5.2.8
Version du client MySQL: 5.0.51a
Extension PHP: mysqli
phpMyAdmin :
Version: 3.1.1
Code PHP :
<?php
$link = mysql_connect("localhost", "root", "mysql")
or die("Impossible de se connecter : " . mysql_error());
echo "Bonjour le monde"," <br /> ";
echo "Connexion réussie"," <br /> ";
mysql_select_db('dev001');
$ouvre=fopen("c:\\tableau2.txt","w+");
$fichier = "";
$select = "SELECT Nom,Serveur_de_réference,Serveur_authentification,IP,Lastlogon FROM computer";
echo $select," <br /> ";
$result = mysql_query($select,$link);
echo $result," <br /> ";
while($row = mysql_fetch_object($result)) {$fichier .= "".$row->champ1.";".$row->champ2.";".$row->champ3.";".$row->champ4.";".$row->champ5."\n";}
fwrite($ouvre, $fichier);
fclose($ouvre);
echo 'traitement terminé.';
mysql_close($link);
?>
Message d'erreur : echo $result;Notice: Undefined property: stdClass::$champ1 in C:\Program Files\EasyPHP 3.0\www\lit_sql_ecrit_dans_fichier.php on line 20
Notice: Undefined property: stdClass::$champ2 in C:\Program Files\EasyPHP 3.0\www\lit_sql_ecrit_dans_fichier.php on line 20
Notice: Undefined property: stdClass::$champ3 in C:\Program Files\EasyPHP 3.0\www\lit_sql_ecrit_dans_fichier.php on line 20
Question :
je ne comprends pas : Undefined property: stdClass
merci pour votre lecture.
--------------------------------------
SOLUCE :
".$row->champ1.";". n'existe pas
donc il faut remplacer :
while($row = mysql_fetch_object($result)) {$fichier .= "".$row->champ1.";".$row->champ2.";".$row->champ3.";".$row->champ4.";".$row->champ5."\n";}
par while($row = mysql_fetch_object($result)) {$fichier .= "".$row->Nom.";".$row->Serveur_de_réference.";".$row->Serveur_authentification.";".$row->IP.";".$row->Lastlogon."\n";}
CdtSaper