0

In web-development, is PHP just a mediator between HTML and SQL? (since HTML cannot access database through SQL directly?)

What all PHP can do with the data accessed through SQL that SQL can't?

PS: I hope this is a very basic question, but googling didn't give me a satisfactory answer. I am a newbie in case of application-level web-development other than just having basic courses about HTML, CSS and PHP completed on codecademy.com. Also kindly correct me if there is anything wrong with my concepts indicated in the above questions. Thanks.

Ambady Anand S
  • 76
  • 1
  • 11
  • While PHP often does mediate between SQL and HTML its is capable of doing many more things and does not require SQL at all. – BigScar Jul 02 '15 at 19:33
  • In your scenario; HTML is how you view data, MySQL is how you store data, PHP is how you control the process of getting data from MySQL to HTML. – castis Jul 02 '15 at 19:34
  • Since PHP is a scripting language and SQL is not, PHP can analyze the data returned from the SQL and makes decisions off of it. – DJMcMayhem Jul 02 '15 at 19:35
  • @BigScar I have heard that PHP is also used as a general-purpose programming language. But here I am mainly interested in knowing its role in web development in relation with HTML and SQL. Thanks. – Ambady Anand S Jul 02 '15 at 19:36
  • @castis Okay, thanks. – Ambady Anand S Jul 02 '15 at 19:49
  • @DJ McMayhem Does it mean that SQL can't be used for decision making because, unlike in PHP, it lacks control-flow statements such as if-else, for loops, etc.? – Ambady Anand S Jul 02 '15 at 19:49
  • @AmbadyanandS exactly! So sql can return the data you need to verify a user, (name, email, password etc.) but PHP has to actually do the verification and see whether or not the correct user is trying to log in. (for example) – DJMcMayhem Jul 02 '15 at 19:51
  • @DJ McMayhem Okay, thanks. :-) – Ambady Anand S Jul 02 '15 at 19:54
  • @DJMcMayhem Please stop spreading terrible advice and have a look at T-SQL for MsSQL and PL/SQL for Oracle. MySQL also supports a language like those but I do not know the name for it. These languages come complete with logic blocks, function calls, and exception handling. – MonkeyZeus Jul 02 '15 at 20:22
  • @MonkeyZeus I'm not recommending it, just explaining the way it's usually used. I didn't know t-sql existed. That looks WAY better than PHP. – DJMcMayhem Jul 02 '15 at 20:25
  • @DJMcMayhem Your previous comments do not support what you've just described. Everything has a time, place, and reason for implementation. It is up to the developer to be aware of the various abstraction layers in order to build a comprehensive system. – MonkeyZeus Jul 02 '15 at 20:29
  • @MonkeyZeus Even if T-SQL include control statements will it be possible for HTML to access DB directly without the help of a server-side programming-language like PHP? – Ambady Anand S Jul 03 '15 at 06:18
  • @DJMcMayhem You are correct, HTML has no native interface for communicating with a server's database and this is because it is a [Markup Language](http://stackoverflow.com/questions/145176/is-html-considered-a-programming-language). If data security is not a concern in your app then you can look into local storage and various Javascript based SQL "Databases" – MonkeyZeus Jul 03 '15 at 13:10

2 Answers2

2

HTML: A markup language. This just represent your webpage.

PHP: A server side programming language.

SQL: A Query language to query to DB.

If you want your website/web app should talk with your server as per user's need then you can use PHP, Java, Python or any other language that can talk with your server.

But to make a query with your SQL Database then you need to run SQL query so that you can get your result from the DB. If you use any No-SQL DB you don't even need to know SQL.

Imran
  • 4,582
  • 2
  • 18
  • 37
2

The flow of a web application is something like this:

  • The user makes a request for a web page via their browser
  • An HTTP request travels to the server
  • The web server hands the request to the server-side language engine (this can be PHP, Python, Perl, .net, and many others)
  • Processing is done by the language engine, which may include interfacing with a database system
  • If you're using a relational database, the interaction with the database is done using SQL. This is a language used to read and write from databases.
  • This program creates a response, which is usually returned as HTML. HTML is not a programming language: it is markup used to represent documents. Some of this response may contain information retrieved from the database.
  • The response travels in the response of the HTTP request
  • The browser renders the HTML

Note that not all web requests are handled by programming engines: most CSS, image and client-side JavaScript assets are text format, and so can be read by the web server and sent straight to the client without further processing. Sites that are not dynamic can also be stored just in HTML on the web server, and do not need a processing language to render them.

Tackling some simple web app tutorials, and reading about how HTTP works, will greatly help your understanding in this area.

halfer
  • 19,824
  • 17
  • 99
  • 186