Skip to main content
GameDev.net gamedev.net
🔒 Locked

[web] SQL vs PHP

Started by Tipotas688 Dec 19, 2010 at 6:29 PM 7 replies 3.3k views
Original Post
Tipotas688
Tipotas688
Yeah so I have created many dynamic ways in php to load content
in a website and I started considering whether SQL is better.

I never liked databases too much so its a chapter I haven't
really expanded on. The thing is I managed creating all the
hard parts in php in order to have my own database format
and not SQL stuff. The question is that is it better to do
it on your own or use SQL stuff, maybe its safer security
wise to create databases instead of reading .txt for example

So should I consider learning SQL and probably .ASP to go
along with it or should I just keep my php classes and
expand on them?

Thanks!
SimonForsman
SimonForsman
Quote:
Original post by Tipotas688
Yeah so I have created many dynamic ways in php to load content
in a website and I started considering whether SQL is better.

I never liked databases too much so its a chapter I haven't
really expanded on. The thing is I managed creating all the
hard parts in php in order to have my own database format
and not SQL stuff. The question is that is it better to do
it on your own or use SQL stuff, maybe its safer security
wise to create databases instead of reading .txt for example

So should I consider learning SQL and probably .ASP to go
along with it or should I just keep my php classes and
expand on them?

Thanks!


you should definitly learn SQL at some point, its very useful, you can still stick with php though (php is perfectly capable of reading data from pretty much any sql database) , its not really about security, but about ease of use, managing textfiles is simply alot more difficult when dealing with large amounts of data.
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
Ravyne
Ravyne
You seem to be muddling up your technologies -- SQL and PHP are two entirely different technologies which do entirely different things. You may have applied PHP to get similar results to what you might have done with SQL, but they are not fundamentally opposing technologies.

By your description, it seems you've used PHP to implement a web page which retrieves data dynamically from your own collection of formatted files residing on the server. What you've essentially done is create a database of sorts, of your own design and implementation. You could just have well have implemented the same PHP-based page, but using SQL to store and retrieve the data.

SQL itself is not necessarily the be-all, end-all of data storage (in fact, non-relational databases like CouchDB have become quite popular in some applications as of late) but you should prefer to adopt established systems over your own one-off solution unless your solution provides a compelling difference to, and advantage over, time-tested solutions such as SQL.

Here are a few advantages something like SQL has over your one-off solution:

1- Its proven. SQL has been deployed in 10s of thousands of applications.
2- Its scalable. SQL databases scale in size to billions of rows. Try doing that in a text file.
3- Its fast. Its been the life work of many very smart people to build SQL engines such that they optimize their search strategy to perform queries optimally. There are probably hundreds of man-years invested in optimization alone. You should take advantage of that.
4- Its distributed. Your SQL database can be run on another machine, or cluster of machines, when your data access needs outgrow a single machine.
5- Its free. There are plenty of good, free SQL servers available -- everything from SQLlite to MySQL. If time is money, then using one of these systems is actually the cheaper alternative to rolling your own.


Now, something like SQL isn't always ideally suited to every problem -- non-relational databases might be better, even flat text files or binary files could be better in some situations, its just a matter of determining what fits the need -- but if something like a relational database can be made to model the data in a reasonable way, then the advantages surely outweigh the cons 95% of the time.
throw table_exception("(? ???)? ? ???");
Tipotas688
Tipotas688
Thanks both of you for the info.

I was aware that the way I posted seemed
to mix the functionality of two completely
different technologies together, I wanted
to just talk about the "database" part
of php :)

I will take in mind the advantages of SQL
although I didn't really want it for huge
amounts of data BUT its scalability seems
really attractive and a think to consider
in the future!

So SQL isn't per say more secure than PHP
implementation, I was thinking that
hacking into a server could potentially
mess with a text file but it could be
harder for an SQL file, I really have no
idea on the matter, that's why I want to
clear the fog. Thanks again!
leiavoia
leiavoia
SQL is usually it's on server/service, so protecting a database or database server is not exactly like protecting your web server, but it's similar.

SQL usually has the added advantage in that you also need permissions on the database level, which means that you can create different users with different levels of permissions.

You can also put a database on a physically separate machine and restrict access to it by IP address, user, or anything else you can think of.
Cygnus_X
Cygnus_X
As pro-security as I am, I think your worry is misplaced. Perhaps I am rushing to judgement, but Many newcomers to web development tend to have ideas of grandeur concerning web security. I can assure you that modern server technology, php and mysql are quite secure against 'hacking into a server' attempts. Your real concern should revolve around sql injection and the value of having strong passwords. Figure out how hack into your site, and you'll have my attention.

As for storing and displaying dynamic user content, databases are the best way to go. No more discussion. Since you are already familiar with PHP I will encourage you to keep doing PHP tutorials, and learn MySql while you're at it.
KevinAnderson
KevinAnderson
SQL:

MySQL is a database.The data in MySQL is stored in database objects called tables.
A table is a collections of related data entries and it consists of columns and rows.
Databases are useful when storing information categorically. A company may have a database with the following tables: "Employees", "Products", "Customers" and "Orders".

PHP:
PHP stands for Hypertext Preprocessor and is a server-side language. This means that the script is run on your web server, not on the user's browser, so you do not need to worry about compatibility issues. PHP is relatively new (compared to languages such as Perl (CGI) and Java) but is quickly becomming one of the most popular scripting languages on the internet.

For more details:
http://www.utkarshsoftech.com/
deepdene
deepdene
SQL is a query language. Meaning you use it to get a dataset back from a database with a certain criteria. It does nothing but puts constrains on the data you get back from a database. The databases are where the data is stored,. The databases have differing technologies for storing the data and serving the data to clients. SQL is just a mechanism for giving a "somewhat" common interface for querying the data contained inside the database. It's generally not considered a standalone language in most instances, you wouldn't construct a full program out of it in most normal situations.

PHP is a language primarily used for constructing web pages. It's a full programming language. PHP can leverage the SQL language to perform queries on databases such as MySQL. PHP has a framework for connecting to a variety of different databases, since different databases have different mechanics for connecting to them and returning data.
phresnel
phresnel

Thanks both of you for the info.

I was aware that the way I posted seemed
to mix the functionality of two completely
different technologies together, I wanted
to just talk about the "database" part
of php

I will take in mind the advantages of SQL
although I didn't really want it for huge
amounts of data BUT its scalability seems
really attractive and a think to consider
in the future!

So SQL isn't per say more secure than PHP
implementation, I was thinking that
hacking into a server could potentially
mess with a text file but it could be
harder for an SQL file, I really have no
idea on the matter, that's why I want to
clear the fog. Thanks again!


Although I am a big advocate of Good Poetry, it appears to me that ordinary posts shouldn't use explicit breaks where not needed. Here is my proposal, making use of automatic line breaking by your internet browser:


Thanks both of you for the info.

I was aware that the way I posted seemed to mix the functionality of two completely different technologies together, I wanted to just talk about the "database" part of php

I will take in mind the advantages of SQL although I didn't really want it for huge amounts of data BUT its scalability seems really attractive and a think to consider in the future!

So SQL isn't per say more secure than PHP implementation, I was thinking that hacking into a server could potentially mess with a text file but it could be harder for an SQL file, I really have no idea on the matter, that's why I want to clear the fog. Thanks again!


This will also improve your document- and email-writing skills, as not all recipients and programs use the exact same font and window width.

Thank you for your attention.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.