Jump to content

black.horizons

Members
  • Posts

    78
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

black.horizons's Achievements

Member

Member (2/5)

0

Reputation

  1. fenway, looks like that should do the job. thanks very much - one more bookmark added to my browser!
  2. is it possible to do that? if so can you provide some example of grouping by arbitrary time periods?
  3. Hey guys, I'm trying to write a query, which is pretty deep but here's the explanation. I need to COUNT() the number of times an event occurs between the hours of 19:00:00 on day 1 and 07:00:00 on day 2. This is easily solved with ... SELECT COUNT(fieldname) FROM table WHERE TIME(fieldname) BETWEEN '2009-12-09 19:00:00' AND '2009-12-10 07:00:00' The problem is that I need to do this query to cover a period of a week with a query for each pair so that I can effectively do this: SELECT COUNT(fieldname) FROM table WHERE TIME(fieldname) BETWEEN '2009-12-09 19:00:00' AND '2009-12-10 07:00:00' SELECT COUNT(fieldname) FROM table WHERE TIME(fieldname) BETWEEN '2009-12-08 19:00:00' AND '2009-12-09 07:00:00' SELECT COUNT(fieldname) FROM table WHERE TIME(fieldname) BETWEEN '2009-12-07 19:00:00' AND '2009-12-08 07:00:00' SELECT COUNT(fieldname) FROM table WHERE TIME(fieldname) BETWEEN '2009-12-06 19:00:00' AND '2009-12-07 07:00:00' and aggregate the results. The only difficulty with doing it this way is that I need to run the query upto 10 times for each day (as there are other conditions which need met and must be selected) which would total 70 queries just to generate one dataset...not to mention the fact that I must run each query twice as I already generate a separate dataset for data between the hours of 07:00:00 and 19:00:00. all help greatly appreciated!
  4. i just didnt think that was a particularly secure way of going about it. storing a user id in a session? i use a md5 hash in the session and look that up in the db - if they match then user is logged in. maybe im wrong about the secure thing?
  5. ok so gmail allows me to login at computer X using Firefox leave that session open and login using IE8 - and the two sessions can work simultaneously. i can then also use computer Y to login at the same time and the sessions still work!!
  6. Hi guys, I've been racking my brains on this one...just trying to figure out how to enable multi simultaneous logins like Google Accounts manages to do. I've also trying to understand how non session based login works...any thoughts on this is/should be done?
  7. put {debug} at the top of your .tpl page and paste in what the popup window says...(if you dont get a popup disable your popup blocker!!)
  8. try putting the literal tag outside the <script type=""> and script e.g. {literal} <script type="text/javascript"> <!-- Sortable.create("results_table", { onUpdate:function(){ alert(Sortable.sequence('results_table').join('')); } }); --> </script> {/literal}
  9. ok, so how would i go about writing an OOP database class without the use of a singleton. are you suggesting that each the database object is passed into each class then and referenced that way?
  10. i took from your saying of not using singletons for databases as you may need to use more than one connection to mean that in a multi server setup it provides a lockin that you don't need - i.e. using a singleton class limits you to one connection - which is a bad thing in a multi server setup...
  11. ok just to continue the naivity - _how_ would a singleton be avoided in a multi server setup. and how is a registry avoided in a multi server setup? I'm actually thinking of an application I'm starting to draw requirements for that would require a multi server setup (multi database servers, multi file servers)
  12. given my relatively basic php database access systems - i have currently never come across the need to have more than one connection. i'm perhaps showing naivity here - but when would you need more than one connection?
  13. ok i think i get it. just to confirm though...the constructor in the database class where the: if($settings){} statement lies... thats where i make the initial database connection so that the class would look a little like this: class Database { private $db_connect; private function __construct($settings = null) { if($settings) { //unserialize $settings array etc first...then... $this->db_connect = new mysqli($domain, $username, $password, $db_name); } } public static function getInstance($settings = null) { if(!self::$instance) { self::$instance = new self($settings); } return self::$instance; } } just a quick aside, I tend to hold my settings hardcoded in the database class, so that i don't have to pass in "settings", is this advisable? obviously in the constructor i could test for a boolean variable so if settings==true then /* store each setting in the data member variables */
  14. Nightslyr, thanks for the clear cut explaination. Fortunately i'm in final year of a software engineering course doing about code management and know about coupling/cohesion. would using the singleton approach be appropriate, or the must appropriate approach for a database object then? Or would this still create many connections on a single page. For obvious reasons I want to keep the connections as low as possible, whilst still accessing all the data I need.
  15. I've been doing PHP for over 4 years now - but only lately (last 12 months) been starting to write it as OOP. I came to the conclusion this week that my code cannot be performing efficiently at all and I've tried to research how to do it better. Various people mention registries and singletons - but i've no idea what these are - even after reading about them! I don't quite understand how they work - but I think I understand their purpose - and I think their purpose is exactly what I want. I _think_ that a database class as a singleton gives an application a single point of call to a database, and drastically reduces the amount of connections. currently my db access in oop goes a little like this: class db{} //this has the mysqli->connect statement and thats all class user($db){} //construct sets $this->db = $db; //this has lots of queries that take place in this class e.g. $db_query = $this->db->mysqli->query("select * from "); //only a dummy query!! I have several class like user each one passing in the $db, and putting queries onto it. In my head that seems like a lot of memory is being used - especially as there are usually 3 or 4 classes - as well as the DB class being used on each page - I think that might result in 4 statements of $this->db = $db; this surely can't be right and singletons / registries sound like what i need. can anybody explain to me a) what a singleton is b) what a registry is and c) how to effectively implement them via short code sample so I can an idea. I've seen people writing "getInstance()" functions - again I've no idea what they are so if that can be summarised too I'd be an extremely happy person!
×
×
  • 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.