Jump to content

ghostcoder

Members
  • Posts

    26
  • Joined

  • Last visited

Posts posted by ghostcoder

  1. Hello,

     

    I have a question for you regarding mysql connections and my php application.

     

    My current application uses old school database access and queries. The thing I've loved about it, is that I can easily run my mysql_query() statement no matter where I am, be it in inline code, functions and even classes. It's nice not having to worry about the database object.

     

    Ok, so, I decided to start rewriting my core application, and I decided to use a myqli object. This is all great and pretty, but now I have to get the datbase object nicely into functions and classes before I can run my queries. I first simply created a new database object, and then passed it in the function call as a variable or set it as a variable when creating a new class object. I also tried putting it into a session variable, and then accessing it via that in functions and classes (which works). Ok all of these solutions work, but I get the feeling they aren't the best method. So, the best method is a Singleton class. I kind of understand that after studying it for a couple of days, but it still seems messy and it will require more code each time I need to call on the database.

     

    I have a very large application, and it queries the database often. It's very lean and very fast right now using the old school mysql_query method. But it's not the 'modern' mysqli object way. So I'm trying to decide if it's worth rewriting most of my code to use a database object.

     

    Is there something wrong with putting a mysqli database object into a session variable?

     

    What is wrong with passing a simple variable to each function or class?

     

    Both of these methods seem to work, but they still aren't as clean and simple as just using the old school method. Especially if I'm only ever using one database.

     

    If you have any thoughts or feedback, I'd appreciate hearing from you.

     

    Thank you.

×
×
  • 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.