What does MySQLi vs PDO Teach You about Development?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
one of the things you have to do as a professional developer is be able to learn things on your own in fact one of the key aspects of the job of a professional coder developer is your ability to learn things on your own when you become a much more mature developer you stop thinking in terms of i am a java coder i am a react developer i am a node developer you start thinking in terms of i'm a developer and i'm going to use whatever technologies i need to use to get this job done there's no perfect language there's no perfect framework they all have their pros and cons and oftentimes the choice of the technology comes down to personal taste invested infrastructure in the business let me unpack that because people might not understand that so if you go work for a company and they may have invested a huge amount of time and effort into some application that's developed with php and you think that php is no good and you think you should do it in javascript or you think you should do it in django or with python you whatever whatever your choice happens to be and in certain circumstances yes node could be better than php in certain circumstances and vice versa java could be better in certain circumstances but at the end of the day if you have a business that's already invested huge amounts of money and they have an infrastructure in php as an example they're not going to want to switch off that doesn't make any business sense and it will make their organizational structure more brittle by having disparate pieces of technology involved in the process so anyway in this video using mysqi and phpdo as the example i want to show people who've done foundation training they're just starting to get into the world of coding as a professional not as a tutorial master as a professional you're just learning your first job maybe you're you've just started or you're about to start your first job whether you're freelancing what not i want to give you some ideas about some realities of the development world and how to search for things some places you might want to go so i'm going to use php pdo and mysql mysql which are extensions in php that allow you to connect to databases i'm going to compare some things about them and show you how to look at them so let's just take a look boom so here we go so one of the things developers have as a tremendous advantage today is the massive amount of information out there in terms of uh well everything so there's just so much out there there's a plethora of information for people who have some decent knowledge in in anything so let me just get that window in place here yeah so if you are somebody who has skills as a developer there's literally unlimited um information out there you can gather whether whether it be through youtube videos or just going to the documentation what i teach people you learn your foundations really well and then you don't really need any other courses you don't need other schools you can just go to documentation and learn what you need to learn so let me give an example so i go to php.net and i go to the manual here and um i'm just choosing php because it's whatever so i go to php and there's two apis that they have two extensions that allow php developers to connect to databases now you have the mysqli extension and you have the php pdo now depending on which programmer you talk to they're going to say well this one's better than the other so for example my course when i've been teaching people how to code since the early 2000s so in my earlier courses i taught mysql which is the first extension they used in php and this only connects to mysql the database mysql so uh that has now been uh removed from php7 can't use it it was deprecated i think in five we're at eight as i record this so mysqli has some significant advantages over mysql things like prepared statements i think there's improvement in terms of speed and i think some security issues been a while anyhow so here's my sqli now let's look at mysqli syntax and code to do a basic connection select operation and then to fetch that record set and to display to an individual so you have mysqli extension number one and you got php pdl so let's look at you have your connection string up here so the connection string for pdl is a little bit different than it is for mysqli but let's say you did my course where i teach my sqli basics i don't believe i teach pdo i may point to it may talk about i don't think i teach it but you know what uh if you know this and you understand this for you to understand this on your own doesn't take a lot of effort right it's pretty easy oh look here's the connection string in fact all you have to do is go to go to google and you type in php pdo connection string boom you're going to get a result and if you know mysqli it's really easy to learn pdo right it's literally takes you about 10 seconds so here's your connection string oh here's yours your uh your query in this case they're using a select statement it looks pretty much the same right it's pretty uh almost identical then you got your result set you're fetching the collection of records pulled from the databases how you do it there's the syntax for pdo and this is syntax syntax for mysqli again pretty similar there's a few little things that's going on here with pdo uh pdo its advantage over mysqli is that it connects to multiple databases as opposed to one so the idea there if ever which will never happen by the way but if ever you write your app and you decide to switch from one database to another as long as pdl supports it and supports many of them i don't know how many now could be 10 20 i'm not sure what it is then you don't have to change any of your database access code if using pdo right you just point to the new database you can go from mysql to posgray as an example and you don't have to change anything because pdo is an abstraction layer meaning it's a layer code that that does the translations for you whereas with mysqli it only connects to mysql that's it now the thing is a little reality i've been coding since 90s i have never seen i have never seen production code move from database a to b it just never happened it's such a rare event uh when you do that kind of thing it's massive changes are being done beyond um just your database access layer so the advantage of being able to switch off uh databases that pdo provides i think it's kind of a it's a really esoteric strange bird of an advantage you know so i wouldn't be so um i wouldn't care too much about that so as we can see here on the php page they actually give you a comparison of both uh extensions so the overall extension excuse me the overall performance of both extension is considered to be about the same of all the performance of the extension contributes only a two only a fraction of the total run time of a php web request often be impacted as low as 0.1 percent yeah so we can see ph yes mysqli pdo uh eight and php seven eight support uh both both in active development uh i recommend for new products they both have op interface uh mysql i has a procedure interface which i wouldn't use i would always stick to the oop interface although some people would debate that of course oh it supports non-blocking synchronous query so that would suggest a performance advantage with mysqli again for most projects this is probably not going to be much of an issue nobody's most people are not going to be working on the next facebook server side prepared statements that's good client-side prepare statement that's interesting that's interesting for pdo we can go on for hours about this but what i wanted to show you is that once you understand the concepts with mysqli for you to pivot to pdo is really a non-issue another thing you can do is you can just go to google and you go should you use php pdo versus mysqli so we got some results w3schools good site i think both mysql and i and pdo have their advantages pdo will work on 12 different databases there's the answer 12 whereas mysql i will only work with mysql database so if you have to switch your project to use another database which will never happen almost never happens pdo makes the process easy both are object-oriented um anyway so you got that so the point is without having to take a course as long as you know your basics of database access with mysqli you can find all the other information you need as a developer very very very quickly so it's p php pdo or secure there's no difference in security so exactly so anyway we can go on and even like so they give an example here where they break down things again the point of this video is not really about pdo and mysqli is to show you how you can use the web once you have basic knowledge to fill in any gaps that you need so they execute their database query here and they echo out the result which is the result set using html entities method or function so what's that i just type in html entities yeah there you go it gives you a nice breakdown tells you what it does that's cool you know gives you all the details again don't need a course right and if you want you just go to site like the w3c html entity is the function so it's a function you click to try it yourself or it did and it actually shows you exactly what happens here right it basically uh converts the characters into attendees often used to prevent browsers from using as an html element if we view source view selection source there you go it uh creates these entity elements right boom boom so this way the code is not this is not interpreted as html is interpreted as plain text by the browser bang bang bang that's where we got that so you can you can insert all kinds of different strings html code in here and the html the html entities will be sure like i'll give you examples let me go um equals ruby all right space run boom that's not good there we go so this is not interpreted as code it's just uh displayed as uh plain text all right there you go so to get back to the point of the video if you are a pro developer if you are a pro developer you have to be able to navigate the web google stack overflow and other sites that are relevant for the technology be working on so if you're going to be working on ios you'd have to go to the apple development resources so what to take away from the video is that as a professional developer you have to get used to being able to find little answers like this again once you know your fundamentals well enough you can learn new stuff and pivot very quickly so in my courses i just teach the fundamentals a couple of basic crud projects and that's pretty much it after that my students are able to do very well as developers and get the job done
Info
Channel: Stefan Mischook
Views: 4,155
Rating: undefined out of 5
Keywords: developervlogs, developermentoring
Id: KRZwgLECfVs
Channel Id: undefined
Length: 13min 19sec (799 seconds)
Published: Thu Jun 10 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.