Hot answers tagged

5

Short answer, no. But mysql_real_escape_string isn't the only thing that protects you here. See : $text = mysql_real_escape_string($_POST['text']); // $_POST['text'] == "1 OR 1=1" $result = mysql_query("SELECT * FROM login WHERE id = $text"); You're not protected here, and an injection was made. So your quotes are protecting you against this here. You ...


5

You're responsible for enhancing and maintaining the codebase. Is that the only responsibility that you have ? If it is, then the game is pretty simple. Start small. DO NOT TOUCH THIS GOD. It's a God for a reason. It is used everywhere, it is too massive and too powerful, you won't be able to test it anyway and any change could break ANY part of your ...


4

No. Unless you are on a really crappy O/S (or, to be precise, your ODBC library and/or database access drivers/library, which may or may not be part of the O/S proper), your code is not actually creating/using/closing database connections. It is creating/using/closing database connection objects, which are a wrapper for the underlying connections. The ...


3

Both solution are viable, they simply don't apply to the same use-cases. a) manipulate the DOM via JavaScript : This result in a more heavy first page, but after that you will use less bandwidth, because you will only fetch what you need, and not rebuild and send everything. And in the cases where you don't need to fetch anything, it will be really quick (...


3

The first question that comes to my mind when reading your question is not how one could refactor such a beast (»1,100 files and 120,000 lines of code.«), it is more »why on earth would anybody do that?« I know the strive for the perfect design and I too love clean code. But ont the other hand, I have only 8h a working day and there are funnier things to do ...


2

Yes, this wastes memory. However, consider this: typical virtual server for a small web site has a few hundred megabytes of RAM allocated to it; for a larger site that might be upgraded to a handful of gigabytes. A typical model object might use up a few kilobytes and have a lifespan of less than a tenth of a second. Now work out how many requests per.second ...


2

Your understanding is correct. Keep in mind that different frameworks use different approaches, so something which would for instance apply to Laravel won't necessarily apply to, say, Symfony. This is especially true when it comes to deciding where the logic goes: some frameworks use models as basic objects containing data, but practically no logic by ...


2

If you have a small, fixed number of different part types which will be seldom extended, you can keep this pragmatic and give your PersisterFactory a handful of different methods like CreateDesignPersister, CreatePlotPersister or CreateSelectionPersister. If each of those classes contains only a single persisting method, even that maybe overengineering, a ...


2

Ahmed, Web pages can be built in just html. In fact, that's how the web started out: with just simple html pages, things we would call today "brochure-ware". The user requests a page and the server delivers a mixture of text and pictures, and then it's done. There is no interactivity, like individual preferences or searching a database. PHP came later ...


2

Preface For any given project, the answer to this question will likely differ. This is simply a result of structure and overall philosophy. It may be easy and straightforward in some instances, but extremely difficult and complicated in others. However, if this is a difficult problem, that is a very strong code smell: something is likely quite wrong with ...


2

It is bad practice to denormalize as you state. Depending on your search criteria, any one of the four tables could be chosen by the query optimization routine. If you are selecting on a package selected from a drop-down list, there should be no reason to add the packages table to the query as you can match the package_id in the package_durations table. ...


2

There's nothing missing from the language itself that would prevent you from doing functional programming. The only thing missing from the runtime is tail call optimization, and you can actually do quite a bit of FP before hitting that limitation. What's really going to hurt you if you try to do FP in PHP is lack of library support for it. You need a ...


1

What you have here is using the Singleton Pattern to ensure that all callers receive the same instance of the connection object. Sounds efficient to being with and, so long as your application is purely single-threaded and never tries to do more than one [database-related] thing at a time, it will probably work quite well. If this is a particularly long-...


1

With a little guidance from @RobertHarvey I found a StackOverflow answer about Presentation Models. A presentation model is a utility class that is used to render data on a screen or report. Presentation models are typically used to model complex data structures that are composed from data from multiple DTO’s. Presentation models often represent a ...


1

What you are decribing is a common design pattern, and, as @Robert commented, its name is abstract factory remember SRP means, that a entity must have only one reason to change not that it must only do one thing at all, or return only one type of result. So no, you are not breaking SRP.


1

I see all websites (THE big ones) make both PHP and HTML in same page .. Do I need to make all my website pages as PHP and embedded HTML inside it ? The fundamental problem here is that you're seeing a thing that websites you perceive as being big ones and then you're assuming that's a good thing to do. It's not. PHP is terrible enough on its own; ...


1

In this example of the command pattern, returning a value is handled with a callback. I would imagine that a future or promise would work just as well. Decoupling of the return type is not mentioned in the example; in systems I've seen that are similar to this where you subscribe to an Event (the moral equivalent of a "generic" callback), one would return ...


1

Usually you have to query DB every time you render a page. Q1 - Yes, you just have to select all items ordered by created date (well, you don't want to select ALL, but only how much you need for current page - see 'Pagination') Q2 - Yes. Same as above. This might not work exactly as you want, because SQL databases are not search engines. In SQL DB you can ...


1

You're confusing whereHas and with. The with method will let you load the relationship only if the query returns true. The whereHas method will let you get only the models which have the relationship which returns true to the query. So here : (new App\User)->with(['address' => function($query){// filter code}])->get(); will return all the ...


1

Php is fine for your project, even though there are better alternatives (hello NodeJS). Ajax won't be real time. You'll have to manually make requests (even if they're made every X seconds) to fetch new datas. There won't be any conflict but there might be performance issue for you and your user. Sockets are more interesting for your project because they'...


1

Ajax has better compatibility, but web sockets are more efficient and simpler (as you won't have to deal with issues about long polling, which can be a hassle to get right sometimes). These days, relatively few browsers support ajax but not web sockets, so my suggestion would be to do it that way, simply for the sake of simplicity. Note that efficiency isn'...


1

It's quite unclear what exactly you are asking. We can't write an Elasticsearch tutorial here. As a rough overview: You should have an ES index that contains all the information you possibly want to search/aggregate/facet and also all or most information you want to display. Your search has two basic parts: The search itself that returns the products. ...


1

PHP is an object-oriented language, or at least it somewhat reasonably supports object-oriented programming. The main idea of OOP is that objects send messages to other objects and those objects then respond to those messages. The metaphor of "messaging" is apt: when you send someone a message, all you can see is their response. You cannot see what they do ...


1

There has been some development with event loops in PHP, mainly ReactPHP, that kind of work like Node.js, by loading an environment, running an application (during the setup you may load data which you know will be the same throughout the entire application lifecycle) and then reacting accordingly on various programmer-defined inputs. The problem with PHP ...



Only top voted, non community-wiki answers of a minimum length are eligible