Duel MySQL Connect

  • Bogey
  • Ounce of 'Zu'
  • Genius
  • User avatar
  • Joined: 14 Jul 2005
  • Posts: 5627
  • Loc: Ozzuland
  • Status: Offline

Post June 21st, 2008, 11:57 am

Alright, I have a problem at my site... I use one class to connect and select a database... all done at the same function... my database name, host, user and the password is defined in the siteConfig. Here is the class that connects and selects that I use...
  1. <?php
  2. class db {
  3.  
  4.   # Class constructor and main
  5.   # function
  6.  
  7.   function connect($constant_url,$select = true) {
  8.     include($constant_url);
  9.     $con = mysql_connect($dbHost,$dbUser,$dbPass) or die(mysql_error() ." ( at line <strong>".  (__LINE__) ."</strong> in <strong>". (__FILE__) ."</strong>)");
  10.     if($con)
  11.     {
  12.       if($select == true)
  13.       {
  14.         $selectdb = mysql_select_db($dbDb) or die(mysql_error() ." ( at line <strong>".  (__LINE__) ."</strong> in <strong>". (__FILE__) ."</strong>)");
  15.         if($selectdb)
  16.         {
  17.           return true;
  18.         } else {
  19.           return false;
  20.         }
  21.       } else {
  22.         return true;
  23.       }
  24.     } else {
  25.       return false;
  26.     }
  27.   }
  28. }
  29. ?>

And the problem can be seeing here.

Go to the forum and you will see that it opens properly and that you can read the topics and everything... now go to guides/tutorials and you will see that the thing tries to connect to mysql using root as a user and my user is not root. Of course the forum uses MySQL so it connects there properly but at the guides/tutorials it does not connect properly.

No where in guides_tutorials.php do I re-define the MySQL variables... I can't find the problem as I use one class and one set of defined functions to connect... how can one variable hold two different information in them? Please help... I'm stuck :!:

The problem occured after I fixed it with a bug where it interpreted the \r\n's... It doesn't anymore :) but it also doesn't work anymore as well :(
Creed - One ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Metallica - Blackened
Sixx:AM - Life is Beautiful
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post June 21st, 2008, 11:57 am

  • George L.
  • Bronze Member
  • Bronze Member
  • User avatar
  • Joined: 05 Nov 2007
  • Posts: 1554
  • Loc: sinister passage
  • Status: Offline

Post June 22nd, 2008, 8:22 am

How many tables do you have?
I do have a drug but it's not like pot or ecstasy it's love that's my drug and it will always be that way
(boogs2007, YouTube,2008) We are heading for something,1985
  • Bogey
  • Ounce of 'Zu'
  • Genius
  • User avatar
  • Joined: 14 Jul 2005
  • Posts: 5627
  • Loc: Ozzuland
  • Status: Offline

Post June 22nd, 2008, 11:45 am

1 Database created by me and it has 9 tables so far...
Creed - One ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Metallica - Blackened
Sixx:AM - Life is Beautiful
  • spork
  • Moderator
  • Silver Member
  • User avatar
  • Joined: 22 Sep 2003
  • Posts: 4867
  • Loc: Rochester, NY
  • Status: Offline

Post June 22nd, 2008, 11:50 am

Let's step back a moment and look at how your code is structured. Why are you using a class for your DB functionality if all it contains is a function? It looks to me like you're calling the function and including a bunch of DB constants from another file. These really should be data members of the class.
  • Bogey
  • Ounce of 'Zu'
  • Genius
  • User avatar
  • Joined: 14 Jul 2005
  • Posts: 5627
  • Loc: Ozzuland
  • Status: Offline

Post June 22nd, 2008, 11:58 am

The reason I do this is because the files are in different directories so the file that is supposed to be included changes from Includes/siteConfig.php to ../Includes/siteCOnfig.php and all of the database constants are stored in the site configuration file
Creed - One ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Metallica - Blackened
Sixx:AM - Life is Beautiful
  • SpooF
  • Ice Cream
  • Bronze Member
  • User avatar
  • Joined: 22 May 2004
  • Posts: 2657
  • Loc: Richland, WA
  • Status: Offline

Post June 22nd, 2008, 12:41 pm

I would suggest that you pass your database information to the function in the class. You can store the values in another file, but one of the idea behind a class is that can be used in more than one instance.
  • Bogey
  • Ounce of 'Zu'
  • Genius
  • User avatar
  • Joined: 14 Jul 2005
  • Posts: 5627
  • Loc: Ozzuland
  • Status: Offline

Post June 22nd, 2008, 1:26 pm

Nevermind... stupid me, I accidentally uploaded the SiteConfig to another directory and for some reason, it was taking that siteConfig rather than the one in the includes... it's all fixed now... thanks :)
Creed - One ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Metallica - Blackened
Sixx:AM - Life is Beautiful

Post Information

  • Total Posts in this topic: 7 posts
  • Moderator: Moderator Team
  • Users browsing this forum: No registered users and 234 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© Unmelted Enterprises 1998-2008. Driven by phpBB © 2001-2008 phpBB Group.

 
 
 

Join Ozzu for Free