PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 21st, 2012, 06:05 PM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,845 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 8 h 37 m 27 sec
Reputation Power: 813
PHP5 - Where does all the evil code come from?

Hi,

even though I'm still quite new in this forum, I've noticed that certain bad code patterns keep popping up. I'm talking about stuff like
PHP Code:
 $query mysql_query('SELECT * FROM users') or die(mysql_error()); 

or document.write() or ancient HTML markup.

It happens so often that you almost have to begin every reply with a long preamble of why this and that is bad and what you should use instead.

I wonder where this code comes from and why it doesn't die out. For example, the MySQLi extension is more than 8 years old. Yet still nobody seems to know it, and instead the 12 year old(!) mysql_ functions keep being used. Do books spread this stuff? Or is it the bad tutorials?

I mean, 12 years ... That's when the Internet Explorer 5 came out, and nobody uses that any longer.

Reply With Quote
  #2  
Old December 21st, 2012, 06:33 PM
AndrewSW's Avatar
AndrewSW AndrewSW is offline
JavaScript is not spelt java
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2011
Location: Landan, England
Posts: 743 AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 22 h 56 m
Reputation Power: 164
It is quite rare to see mysqli on forums. I suppose people starting out associate PHP and MySql and think mysqli must be something more advanced . I suppose, also, there must be so much legacy code out there that is never updated. (It is largely a question of just replacing mysql with mysqli. Although, migrating to the object-version or PDO would be preferable.)

We constantly see ancient JS code (language="JavaScript1.6"!!) as well. I suppose most JS tutorial-sites were written many years ago and never updated; and, generally, their pages don't show a date.

My personal bug-bear (although off-topic - sorry!) is the use of form, button, image, etc.. as variable names (in JS and others). People show a distinct lack of imagination . It makes their code very difficult to read and might bite them some time in the (near) future.

Last edited by AndrewSW : December 21st, 2012 at 06:39 PM.

Reply With Quote
  #3  
Old December 21st, 2012, 06:57 PM
ptr2void ptr2void is offline
I haz teh codez!
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Dec 2003
Posts: 2,476 ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 4 h 42 m 37 sec
Reputation Power: 2194
Google PHP MySQL Tutorial and see what the first few links pull up. You'll have your answer.
__________________
I ♥ ManiacDan & requinix

This is a sig, and not necessarily a comment on the OP:
Please don't be a help vampire!

Reply With Quote
  #4  
Old December 21st, 2012, 07:11 PM
AndrewSW's Avatar
AndrewSW AndrewSW is offline
JavaScript is not spelt java
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2011
Location: Landan, England
Posts: 743 AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 22 h 56 m
Reputation Power: 164
They should have named it MySql2, then the intent is obvious (I myself tend to forget that the i stands for 'improved').

Reply With Quote
  #5  
Old December 21st, 2012, 11:16 PM
drumn4life0789 drumn4life0789 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2008
Posts: 129 drumn4life0789 User rank is Sergeant (500 - 2000 Reputation Level)drumn4life0789 User rank is Sergeant (500 - 2000 Reputation Level)drumn4life0789 User rank is Sergeant (500 - 2000 Reputation Level)drumn4life0789 User rank is Sergeant (500 - 2000 Reputation Level)drumn4life0789 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 23 h 1 m 20 sec
Reputation Power: 10
It is because there is so many tutorials out there using the old way of doing things and they still dominate the search engines.

Reply With Quote
  #6  
Old December 22nd, 2012, 02:21 AM
aeternus's Avatar
aeternus aeternus is offline
For POny!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Location: Amsterdam
Posts: 416 aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 5 Days 4 h 56 m 43 sec
Reputation Power: 114
Quote:
Originally Posted by drumn4life0789
It is because there is so many tutorials out there using the old way of doing things and they still dominate the search engines.

That probably is it.
__________________
PHP Tutorial

Reply With Quote
  #7  
Old December 24th, 2012, 11:26 AM
navnav's Avatar
navnav navnav is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Location: Oxford, United Kingdom
Posts: 40 navnav User rank is Private First Class (20 - 50 Reputation Level)navnav User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 2 h 18 m 23 sec
Reputation Power: 1
Send a message via Skype to navnav
Well I think people just use mysql_* because they think it's easier. And tbh, it looks it too. At least, from a beginners view.

I think it's also down to OOP. Most beginners are not just beginners to PHP, but beginners to programming in general. So they see the OOP approach and they think 'WTF'. I know I did it when I first started.

Although PDO and MySQLi is beginning to over take mysql_* in most search results, there are still high ranked sites advising people to use the old mysql_* ways - such as w3schools.

But give it some time and keep advising people to use PDO/MySQLi, and hopefully, this mysql_* rubbish will be at an end.

Well actually, mysql_* has now been depreciated in the latest version of PHP. So when hosts start updating their PHP versions, we should see some better results.

Reply With Quote
  #8  
Old December 26th, 2012, 06:37 PM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,845 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 8 h 37 m 27 sec
Reputation Power: 813
You're probably right about the bad tutorials. I'm still baffled by how much influence they have. It's like every single newbie reads the same bad tutorial, because they all use "mysql_query() or die(mysql_error())".

It's so sad. I'm waiting for a PHP version that will finally remove the old baggage and force people to update their sh*t. Or will we have to same discussion in 10 years?

I'm not sure, but this seems to be a PHP issue. In Ruby, for example, you do have people still using the old (and now deprecated) version, but you won't find code somebody has dug out of an 90s tutorial like it's the case with PHP.

Reply With Quote
  #9  
Old December 26th, 2012, 06:57 PM
richpri's Avatar
richpri richpri is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Location: Chicago
Posts: 49 richpri User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 27 m 23 sec
Reputation Power: 1
Facebook
As I was forcefully reminded earlier today: Its deprecated not depreciated.

Reply With Quote
  #10  
Old December 27th, 2012, 01:51 AM
Hall of Famer Hall of Famer is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Location: Ithaca
Posts: 64 Hall of Famer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 4 m 57 sec
Reputation Power: 1
Well MySQLi is in somewhat of an awkward situation. The advanced programmers tend to use more powerful and flexible PDO, while beginner coders just stick to mysql basic functions since they dont know OOP. Where does MySQLi fit in the picture? Sure some people use it for preference, but its really isnt that special.

Id say the reason why some people stick to mysql_query() or die() is that this has been the way they were taught PHP. For procedural programmers, thats probably sufficient for their web development. Sure it has issues, but in many circumstances a beginner coder only realize the severeness of the issue once they are hit hard. Its difficult to change the old habit once it grows on you. PHP is easy to learn and use, but on the other hand it does not promote good application design.

Reply With Quote
  #11  
Old December 27th, 2012, 07:11 AM
richpri's Avatar
richpri richpri is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Location: Chicago
Posts: 49 richpri User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 27 m 23 sec
Reputation Power: 1
Facebook
I am a 66 year old programmer/DBA/network engineer/retired person. I have been coding a LAMP application as a hobby for about 2 years. [Wow! No schedules! No time pressure! [ Ahem, back to the topic Rich.]] I started out using the old MYSQL API. [I was totally unaware that it was deprecated.]

Earlier this year I found out. I immediately stopped working on the project, did a survey of the two alternatives and gave my self a brief crash course on mysquli, my choice over PDO. I am currently recoding all database access to take advantage of this new API.

My point is that some of the users of the old API are probabily doing it out of ignorance. Putting a brief note about mysquli and PDO in all those out of date examples could work wonders!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP5 - Where does all the evil code come from?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap