Hi I am currently a high school grad and I know full stack javascript and man those promises and callbacks are hell but you can ignore that. I am studying PHP right now. Do you think should I jump to laravel instead of learning the mysqli part in php? Or is it also essential to learn in laravel. I already know the OOP part of php.
I would recommend learning SQL, yes, though there’s no reason you can’t do that at the same time as a framework, or at least pick up the framework after picking up the basics of SQL. For that, you want PDO, not mysqli/mysqlnd (the old mysql extension is gone). It’s largely just an OO interface over the same APIs, but it’s also the de facto standard for DB access, and lets you change databases relatively easily. Don’t underestimate the usefulness of portability: you might always use mysql for your main database, but you’ll also want sqlite for tests.
You can get away with never knowing SQL and using just an ORM for quite a bit, but Laravel’s Eloquent isn’t especially a full abstraction: once you need to do a join, or a DB::raw to use a function, you’ll be happy you picked up the sql knowledge. To say nothing of when you make a typo or botch the declaration of a relation and it spits out raw sql errors at you to debug.
I think it’s best if you have a grasp on SQL in general so when writing queries—whether raw ones with mysqli_*
, PDO, or using something like Eloquent or an ORM—you know what’s happening. Then it doesn’t matter what you use.
Thank you for your replies really appreciated!!
Laravel is using something called eloquent models and basicly, its working out of box after install so the only thing which is necessary is providing db credentails in env, you’re not using sql just eloquent model api. This is common in framework’s that part of native sql is under layer of abstraction.
I wouldn’t say it’s essential, but it is useful. What’s more useful is understanding how to write data queries (SQL?) and how to get their results and loop over. When you understand those basics, you can easily find the syntax for whatever data abstraction layer you’re using.
For example, in Laravel (using Eloquent) you might write: $user->where(’email’, $email)->get();
In vanilla php you might: $sql = “SELECT * FROM users WHERE email = $email”; $mysqli->query($sql);
The important thing to know is how you can get a user with that email address out of the database. The rest is syntax, and even with more than a decade of experience under my belt, I still usually google the syntax (or copy/paste from my codebase) to get it right.
(With more questions, please use r/phphelp which is friendlier to how-to questions.)
In vanilla php you might: $sql = “SELECT * FROM users WHERE email = $email”; $mysqli->query($sql);
Please don’t actually write it like this. You’d write something more like:
This prevents SQL injection attacks, a very common problem.
Members
Online