Daniel0
Staff Alumni-
Posts
11,885 -
Joined
-
Last visited
Everything posted by Daniel0
-
How in the world would you do that? If that was possible then it would be possible to load all sorts of malware on people's computers.
-
Have a read over this: http://en.wikipedia.org/wiki/Database_normalization It won't solve your issue, but your database isn't normalized.
-
PHP is an imperative programming language. It's sort of like a recipe: first you do this, then you do that. Maybe if you try to explain what you are actually trying to do we'll be able to help you.
-
OOP Databases Singletons and Registries
Daniel0 replied to black.horizons's topic in Application Design
I don't understand your question. The registry and singleton patterns have nothing to do with a multi-server setup. -
when i do a file include that has Global vars set, it affects the entire page Why do you think global variables are considered bad design and bad practice?
-
OOP Databases Singletons and Registries
Daniel0 replied to black.horizons's topic in Application Design
The idea of a registry is to have a gigantic hole to dump data in and take data out of in runtime. Things like configuration information or other things that are often used throughout the entire application. It's a bad idea though. -
Didn't I just provide examples of real world applications? The XMLable and JSONable interfaces and the abstract database super class. You can also take a look at the observer pattern. It usually uses an interface for the subjects and observers.
-
Remove the quotation marks around the table name.
-
Then disable the execution time limit. set_time_limit
-
or die() is bad practice. At the very least use trigger_error instead of die(). In that way you can still control the error reporting.
-
date and time that are auto inserted into my database are wrong
Daniel0 replied to sandrine's topic in PHP Coding Help
NTP is short for Network Time Protocol. It's a protocol for synchronizing clocks. You can only set that up if you are the administrator of the server. I don't know if your server's clock is off though. You can check that yourself by echoing the date and time to see if it's correct or not. -
How doesn't it work? It just doesn't update or do you get any errors of any sort? Maybe try to echo the query to see that it's generated correctly. Also, for future posts, could you please put or [php] tags around the code you are posting?
-
Complete unrelated, but you might want to refactor mobile_device_detect() and learn about commenting. You're going way overboard with your comments.
-
mysql_query
-
Of course it doesn't work. You aren't executing the query... You are just defining a variable containing the query.
-
Dude, fill out a patent application quickly!
-
The header image, though it looks nice, is way too large. Virtually no content is visible above the "fold" (the stuff you immediately can see without scrolling). I don't like the side bar menu gradients. I think they should be smaller and reversed. Otherwise I think it looks pretty nice.
-
It would be better to setup load balancing on server level instead. http://httpd.apache.org/docs/2.2/mod/mod_proxy_balancer.html
-
That presupposes your method/code is good. Perhaps you should read the "how to ask questions" HOWTO linked to in my signature.
-
Besides providing code with syntax errors, maybe it would also be a good idea to read the question...
-
function str_replace_count($search, $replace, $subject, $limit) { for ($i = 0, $replaceLength = strlen($replace); $i < $limit && ($pos = strpos($subject, $search)) !== false; $i++) { $subject = substr_replace($subject, $replace, $pos, $replaceLength); } return $subject; } $string = 'foo foo foo foo foo foo foo'; echo str_replace_count('foo', 'bar', $string, 3); // bar bar bar foo foo foo foo
-
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_time-format
-
http://dev.mysql.com/tech-resources/articles/hierarchical-data.html Explains the adjacency list model and the nested set model (aka the modified preorder tree traversal algorithm).
-
The idea of an interface is to ensure that a class implements a particular interface. The interface of a class is the public methods it exposes, so in the following class: class Foo { public function fooA(); public function fooB(); private function fooC(); } The interface would consist of the methods fooA() and fooB(). So if you have these interface: interface XMLable { public function getAsXml(); } interface JSONable { public function getAsJson(); } Then you know that if an object is an instance of XMLable then its interface is guaranteed to have the method getAsXml(). Same thing goes for JSONable, but with getAsJson() instead. There is no reason why a class couldn't have functionality for both representing itself using XML and JSON, so it can implement both interfaces if necessary. This can be checked at runtime. Example: // this is within some arbitrary class public function returnAjaxResponse(JSONable $obj) { echo $obj->getAsJson(); } public function generateConfigFile(array $objects) { $return = "<config>\n\t<items>\n"; foreach ($objects as $object) { if (!$object instanceof XMLable) { throw new InvalidArgumentException('All objects must implement the XMLable interface.'); } $return .= $object->getAsXml(); } $return .= "\n\t</items>\n</config>\n"; return $return; } If you have this class: class Something extends Parent implements Foo, Bar Then it is an instance of both Something, Parent, Foo, and Bar, and instances of Something will pass instanceof checks and type hinting as seen in generateConfigFile() and returnAjaxResponse(), respectively. An abstract class is conceptually different. It can be said to be abstract in the sense that it's incomplete, or it's a generalized version of something. You might have an abstract class that represents a wrapper around a database. Considering it contains general information that applies to all databases, but no particular database, it cannot be used individually. It could possibly have declared abstract methods that descendants need to implement. A subclass of that could be one that knows how to connect specifically to MySQL databases, or Oracle, or DB2, etc. Either way these are concrete implementations of the abstract super class, and insofar they implement the super's abstract methods, this is perfectly fine. Abstract methods can be both public, private or protected, but methods declared in an interface can only be public because interfaces are just for ensuring that a given objects implements a particular interface, i.e. has defined set of public methods implemented. Ken's example, while it does illustrate how an interface can be used, actually fails to use interfaces correctly. A square is a shape and as such, Shape should actually have been a (abstract) class. A problem people often have with understanding the differences between interfaces and abstract classes is that they seemingly allow you to do the same thing, i.e. ensuring that you have certain methods, but they are conceptually different and are used for different purposes. I hope the examples I've given illustrate the difference in usage.