PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > include files...
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
include files...

Réponse
 
LinkBack Outils de la discussion
Vieux 15/02/2008, 20h23   #1
fb
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut include files...

Hi everyone. I have the following code stored in a file called
"dbConnect.php".
I include it in a number of .PHP files (at the top of the file) with the
line -- include ('dbConnect.php');
I also close the connection at the bottom of the file.

For some reason it doesn't seem to connect. I try to SELECT items from
the database, but it doesn't return anything. However, if I just
cut-and-paste the contents of the file into the top of the page, it
works fine. Am I doing something wrong?


# dbConnect.php
$hostname = "localhost";
$dbuser = "root";
$dbpassword = "myPass";
$dbname = "cert";

$con = mysql_connect("$hostname","$dbuser","$dbpassword") ;
if (!$con){
die('Could not connect: ' . mysql_error());
}
mysql_select_db("$dbname", $con);
  Réponse avec citation
Vieux 15/02/2008, 23h24   #2
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: include files...

fb wrote:
> Hi everyone. I have the following code stored in a file called
> "dbConnect.php".
> I include it in a number of .PHP files (at the top of the file) with the
> line -- include ('dbConnect.php');
> I also close the connection at the bottom of the file.
>
> For some reason it doesn't seem to connect. I try to SELECT items from
> the database, but it doesn't return anything. However, if I just
> cut-and-paste the contents of the file into the top of the page, it
> works fine. Am I doing something wrong?
>
>
> # dbConnect.php
> $hostname = "localhost";
> $dbuser = "root";
> $dbpassword = "myPass";
> $dbname = "cert";
>
> $con = mysql_connect("$hostname","$dbuser","$dbpassword") ;
> if (!$con){
> die('Could not connect: ' . mysql_error());
> }
> mysql_select_db("$dbname", $con);
>


What do you get for an error message when you try to SELECT?
mysql_error() is your friend.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

  Réponse avec citation
Vieux 16/02/2008, 00h15   #3
Scott
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: include files...

fb wrote:
> Hi everyone. I have the following code stored in a file called
> "dbConnect.php".
> I include it in a number of .PHP files (at the top of the file) with the
> line -- include ('dbConnect.php');
> I also close the connection at the bottom of the file.
>
> For some reason it doesn't seem to connect. I try to SELECT items from
> the database, but it doesn't return anything. However, if I just
> cut-and-paste the contents of the file into the top of the page, it
> works fine. Am I doing something wrong?
>
>
> # dbConnect.php
> $hostname = "localhost";
> $dbuser = "root";
> $dbpassword = "myPass";
> $dbname = "cert";
>
> $con = mysql_connect("$hostname","$dbuser","$dbpassword") ;
> if (!$con){
> die('Could not connect: ' . mysql_error());
> }
> mysql_select_db("$dbname", $con);

Start with something simple in your include file such as:

<?php
echo "Include file works.";
?>

Then at least you will know your file is getting call at all.
Then you can ascertain if the code is incorrect.

When you call the file exclude the ().

include 'dbConnect.php';

Scotty
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 11h48.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12637 seconds with 11 queries