Databases in NativePHP0:00
Let's talk about databases. 'cause this is a really important topic. Almost all of your applications will use a database and in native PHP, it doesn't out of the box support MySQL or Postgres or any of the other database drivers except SQ L light. And there's a really important reason for that. NativePHP applications are gonna be distributed to your users on their devices, and you can't really control
Why SQLite Is Default0:30
to your users on their devices, and you can't really control or know what other software they've got available. So they might not have MySQL or Postgres or another database server. So the best option is SQL Light. SQL Light is incredibly good for this kind of use case where we're shipping software to the user and we need a database on their side that we can operate with reliably.
Considering Other Engines0:58
and we need a database on their side that we can operate with reliably. So you should take some time to familiarize yourself with the differences in SQL Light and how Laravel works with that in migrations and in your models. We do often get the question about other database engines support, and I need to talk about that a little bit here before we go any further. Technically, native PHP for desktop
before we go any further. Technically, native PHP for desktop could support other database engines. Maybe you are deploying an application to computers that you control, and so you know that they've got, say, MySQL running on them. Then you might want that application to connect to that MySQL instance. Or perhaps you've got a network, a closed network
that MySQL instance. Or perhaps you've got a network, a closed network of machines, and you want to have an application that can speak to a central Postgres database that you've got on a closed off server somewhere. You can build the PHP binaries for yourself with those extensions added in for that specific use case. On mobile, this is almost certainly not what you want, and there's a really important reason for why we don't want to connect to databases that don't run on our device
Remote Database Security Risks2:15
and there's a really important reason for why we don't want to connect to databases that don't run on our device and over the open network. The most important one is security. You should not, and I would even say you must not connect to your remote database over the internet using credentials that are stored in your application. You've got your application here, this is your development version. You package that up and you're shipping it to your users
this is your development version. You package that up and you're shipping it to your users and they're installing it on their device. How did they get the credentials to connect to your database server that lives on a server way out in the cloud? The only way is if you give them your credentials. The problem, hopefully, as you can see straight away, is that is never good.
Using an API Layer3:08
The problem, hopefully, as you can see straight away, is that is never good. Those are secrets that you shouldn't be giving out to anyone. You need to keep tight control on those. If you want to provide fine-grained control, high levels of security and identification of your user that's connecting to your database and the best levels of performance for your database, then you need an API layer in between your users
and the best levels of performance for your database, then you need an API layer in between your users and your database server. And I think it's a really good opportunity to build an API if you've never done that using Laravel, a Laravel application that you deploy to your server in front of your database, that your mobile or desktop applications can then speak to. The key thing to take away from this lesson is use SQ l Light.
SQLite Takeaway and Next Lesson4:03
The key thing to take away from this lesson is use SQ l Light. It's the main database that shipped with your applications through native PHP. We set it up for you. We run migrations for you. It's very, very easy to use and it's very performant and with Laravel and eloquent on top. It's incredible. If you've been on the fence about using SQL L in production, I think after you've been using it in these environments,
L in production, I think after you've been using it in these environments, when you're building native applications, I think you're gonna love it. The next question that we're gonna touch on in the next lesson that we get quite often is, can I use this larva application to build a mobile and desktop app? Let's find out the answer.
Let's find out the answer.
