Jump to content

Unable to use connection to MySQL


Karaethon

Recommended Posts

I'm suddenly having trouble using my connection to my MySQL database... (yes it was working but now...)

I have the Connection created in an include file and stored in variable $DB, in the main file that includes the file containing the$DB there are other includes for classes. These classes are SUPPOSED to use $DB to connect to and SELECT/UPDATE/INSERT, but for a reason I cant figure out they suddenly stopped seeing $DB. it keeps saying its an undefined variable.

If you need to see code I can post...

Link to comment
Share on other sites

On 3/31/2019 at 7:58 PM, requinix said:

:psychic:

What's changed recently?

Thats what  I can't figure out. I undid and rolled back my changes and it still won't work.... I decided to give each class its own mysqli_connect and live with it.

Link to comment
Share on other sites

Obviously, code is required if you really want us to try and help...  BUT - please - only the relevant code?  Like maybe the method that does the connection and the code that calls it and tries to go further after making/not making the connection.

Link to comment
Share on other sites

13 hours ago, Karaethon said:

Thats what  I can't figure out. I undid and rolled back my changes and it still won't work.... I decided to give each class its own mysqli_connect and live with it.

This reminds me of the old programmer joke about the code that calculates 1+2 and returns the value 4.

To fix, the programmer adds:  if (result = 4 then result = 3).

In other words, it is never a good idea to work around something like this that should work, but doesn't.  When Requinix asked what changed, we were expecting something like:  "Upgraded to PHP 7" or "I added a new library" or "I am refactoring the database class."

Sounds to me like you went and made your codebase a lot less DRY, which made it worse.  

Link to comment
Share on other sites

I haven't made any system changes, only code changes, after undoing everything I still have no link. But like i said above, I'm giving eah class its own connection to the table it specifically uses. I would like the code reusability of a MySQL_Interface class but I can live with this a I can target specific table per class.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.