This is a discussion on variable problem within the alt.comp.lang.php forums, part of the PHP Programming Forums category; hi in bd.php i do: <?php $serveur = "localhost"; $utilisateur = "root"; $motDePasse = ""; $base = &...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
hi
in bd.php i do: <?php $serveur = "localhost"; $utilisateur = "root"; $motDePasse = ""; $base = "laboiteaprog"; $link = ""; function connectionbd() { //ouvre une connection $link = mysql_connect($serveur, $utilisateur, $motDePasse); mysql_select_db($base) or die("Connexion ratée"); } ?> don't get error in news.php i do: <?php include("bd.php"); .... ?> in news.php i get this error: Undefined variable: serveur Undefined variable: utilisateur Undefined variable: motDePasse Undefined variable: base .... any idea to resolve that? -- Borland rulez http://pages.infinit.net/borland |
|
|||
|
"Marc Collin" <os2@videotron.ca> wrote in message news:2Njjc.44481$Tu2.945553@weber.videotron.net... > hi > > in bd.php i do: > > <?php > > $serveur = "localhost"; > $utilisateur = "root"; > $motDePasse = ""; > $base = "laboiteaprog"; > $link = ""; > > function connectionbd() > { > //ouvre une connection > $link = mysql_connect($serveur, $utilisateur, $motDePasse); > mysql_select_db($base) or die("Connexion ratée"); > } > ?> > > don't get error > > > in news.php i do: > > <?php > > include("bd.php"); > ... > ?> > in news.php i get this error: > > Undefined variable: serveur > Undefined variable: utilisateur > Undefined variable: motDePasse > Undefined variable: base > ... > > any idea to resolve that? > > Either globalize the variables inside the function. OR call the function like this: connectionbd ($serveur, $utilisateur, $motDePasse, $base, $link) Hope this helps RG |
|
|||
|
"Marc Collin" <os2@videotron.ca> schreef in bericht news:2Njjc.44481$Tu2.945553@weber.videotron.net... > hi > > in bd.php i do: > > <?php > > $serveur = "localhost"; > $utilisateur = "root"; > $motDePasse = ""; > $base = "laboiteaprog"; > $link = ""; > > function connectionbd() > { > //ouvre une connection > $link = mysql_connect($serveur, $utilisateur, $motDePasse); > mysql_select_db($base) or die("Connexion ratée"); > } > ?> > > don't get error > > > in news.php i do: > > <?php > > include("bd.php"); > ... > ?> > in news.php i get this error: > > Undefined variable: serveur > Undefined variable: utilisateur > Undefined variable: motDePasse > Undefined variable: base > ... > > any idea to resolve that? > > > -- > Borland rulez http://pages.infinit.net/borland Marc , I do not think you get the eror when including the bd.php. You probably get the error when calling the function connectionbd() definend in bd.php. The variables you are declaring in bd.php will be invisible inside the function connectionbd(). To solve this problem declare the variables inside the function or pass them as parameters to the function or declare them as global variables or create a class which wil take care of the connection. Also read http://nl3.php.net/variables.scope for more information about the subject HTH Rob |
![]() |
| Thread Tools | |
| Display Modes | |
|
|