Database connection & Migrations - Part 3 | PHP MVC Framework from Scratch

Database connection & Migrations - Part 3 | PHP MVC Framework from Scratch

The Codeholic

3 года назад

22,073 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@jerryvargas8363
@jerryvargas8363 - 07.11.2023 07:23

if anyone has problems running the migration again when "php migrations.php" is ran so you can add "m0002_add_password_column" modify the "$SQL" variable your "m0001_initial" to look like the following:


ORIGINAL/VIDEO
$SQL = "CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
email VARCHAR(255) NOT NULL,
firstname VARCHAR(255) NOT NULL,
lastname VARCHAR(255) NOT NULL,
status TINYINT DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=INNODB;";


ALTERED/ FIXED

$SQL = "CREATE TABLE IF NOT EXISTS users (
id INT AUTO_INCREMENT PRIMARY KEY,
email VARCHAR(255) NOT NULL,
firstname VARCHAR(255) NOT NULL,
lastname VARCHAR(255) NOT NULL,
status TINYINT DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=INNODB;";



Zura, If you have already run the php migrations.php command and it successfully applied the initial migration (m0001_initial.php), it should have recorded this migration in your migrations table. If you add a new migration file (e.g., m0002_add_password_column.php) and run the php migrations.php command again, your migration system should check the migrations table, see that m0001_initial.php has already been applied, and proceed to apply any subsequent migrations (in this case, m0002_add_password_column.php).? would that be correct? it looks like it worked for you but In my case i had to alter the SQL statement?

Ответить
@iBusik3G
@iBusik3G - 24.05.2023 00:21

How is the down() method triggered?

Ответить
@learntoswim512
@learntoswim512 - 24.04.2023 22:28

Any advice for help with the migrations? I saw this comment on free code camp since it wasn't working the original code:

className = pathinfo($migration, PATHINFO_FILENAME);
$class = "app\migrations\\" . $className;
$instance = new $class;
echo "Applying migration $migration ..." . PHP_EOL;
$instance->up();
echo "Applied migration $migration" . PHP_EOL;

When I try to substantiate an instance with new $class, I get the following error: Cannot declare class m0001_initial, because the name is already in use. No namespace on a m000 files. Thanks!

Ответить
@ahmedyoussef7968
@ahmedyoussef7968 - 23.03.2023 16:36

Thanks a lot 💚

Ответить
@PeterMumford
@PeterMumford - 22.02.2023 19:53

fascinating stuff. I did have to resolve a bug on line 35 of Database.php. I had to instantiate the migration classes prefixed with the namespace:
$className = 'app\migrations\\' . pathinfo($migration, PATHINFO_FILENAME);
$instance = new $className();
I'm not sure why I needed this on my environment. Maybe my autoload isn't set up right. After I added the namespace, the migrations did run correctly.

Ответить
@user-wo1mh8cw3w
@user-wo1mh8cw3w - 01.01.2023 15:41

what is the name of the theme u r using

Ответить
@hayatzee8830
@hayatzee8830 - 09.11.2022 15:32

Thanks to the best PHP teacher <3

Ответить
@fleckenfurz77
@fleckenfurz77 - 29.10.2022 14:50

Simply awesome how you demystify the features that laravel, symfony, etc have!

Thx a lot for this great tutorial! Learnt a lot!

Ответить
@kevinnacario359
@kevinnacario359 - 05.10.2022 05:29

<3

Ответить
@asadbekdeveloper4599
@asadbekdeveloper4599 - 29.09.2022 22:41

Thank you Zura . Never stop teaching us 🙂🙂🙂🙂

Ответить
@Gandobilis
@Gandobilis - 09.08.2022 12:46

💫

Ответить
@ashiktopu8134
@ashiktopu8134 - 22.06.2022 13:16

Hey, man. Can you please make a video about ORM and DBAL?

Ответить
@armineyvazi9492
@armineyvazi9492 - 17.05.2022 22:23

hame to bootcamp parashon rikhte

Ответить
@armineyvazi9492
@armineyvazi9492 - 17.05.2022 22:23

soltani dadash

Ответить
@armineyvazi9492
@armineyvazi9492 - 17.05.2022 22:23

damet garm

Ответить
@ayoubbablil6990
@ayoubbablil6990 - 04.03.2022 22:09

hello , its okey if i used mysqli instead of pdo ?

Ответить
@ahmedal-raii8184
@ahmedal-raii8184 - 23.01.2022 21:00

Good Job, Please keep making such good content on php

Ответить
@ylmazkadan568
@ylmazkadan568 - 01.11.2021 13:55

I was quite mesmerized. I can swear it's the best tutorial series I've ever seen in my life. Your content is very high quality. Thanks to you, I learned very well how Laravel and similar frameworks are developed. When I'm bored, I watch the video series. I will code soon. Gold content. thank you so much

Ответить
@mouradeljayi584
@mouradeljayi584 - 21.08.2021 14:54

how we can execute the down method from terminal ?

Ответить
@maelstrom57
@maelstrom57 - 08.08.2021 03:05

This series is excellent. Great job.

Ответить
@JesperSkelgaard
@JesperSkelgaard - 16.06.2021 15:24

Great ways todo alot of the items, but i suggest to change the following:
change in .env file to be DB_DSN = "..." or do one parameter for each and create your own DSN string
which makes you able to do
$env = parse_ini_file(dirname(__DIR__).'\.env');
and no need for depending on vlucas/phpdotenv

Ответить
@Kay8B
@Kay8B - 01.06.2021 15:06

For anyone having issues with Uncaught PDOException: SQLSTATE[3D000]:

for some reason putting the port last worked for me.

mysql:host=localhost;dbname=dbname;port=3306

Ответить
@issaissifou4959
@issaissifou4959 - 25.04.2021 15:31

Thank you so much!

Ответить
@mustafaagha8834
@mustafaagha8834 - 15.04.2021 03:07

Awesome tutorial

Ответить
@denyserurangwa9581
@denyserurangwa9581 - 11.01.2021 01:29

Hello!! So cool! Am a new lunix mint user. Been trying to run migrations with no success. Please help😊. Watched tones and tones of videos but it's not working😫. Wanna be able to follow the creation of the framework alongside.

Ответить
@flavius4021
@flavius4021 - 29.12.2020 20:26

Interesting video but I dont like the idea of using php in a view file, or generate dynamic html in a php file

Ответить
@atifraja7410
@atifraja7410 - 23.12.2020 11:02

Hi, Thanks for your video and i have a problem on migration idont know how to handle this the problem is "Fatal error: Uncaught PDOException: SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected in C:\xampp\htdocs\myFrameWork\core\Database.php". can you please tell me what wrong with it? Thanks!

Ответить
@belafekete3125
@belafekete3125 - 10.11.2020 18:31

Hi!
I really like your video. Until this part, everything went well and everything was okay, but now I got this error message:
Fatal error: Uncaught PDOException: SQLSTATE[HY000] [2002] No such file or directory.
I'm using XAMP on macOS Catalina 10.15.7.

Ответить
@timwuuk
@timwuuk - 23.10.2020 19:57

Again great tutorial. Got migration class not found in core folder error when run migration. I know it should search migrations folder rather than core folder. I follow exact every steps including add require_once in the applyMigrations function. Any body can help? thanks

Ответить
@mohammadtaheri98
@mohammadtaheri98 - 02.10.2020 22:22

hi, i have a problem with connecting to database. i'm using lampp for mysql and for my other projects work just fine. but in this project i face this error: Uncaught PDOException: SQLSTATE[HY000] [2002] No such file or directory . i run this project with php -S and without database connection work perfectly. can you help me with this? i setup virtual host for this project but also not working. i also install mysql-server with terminal but no diffrence. running ubuntu 20.04 .

Ответить
@geneartista9714
@geneartista9714 - 03.09.2020 00:50

Create a tutorial using AJAX sir, I`m quite curious on how you do it

Ответить
@geneartista9714
@geneartista9714 - 23.08.2020 23:15

Is this how also in Frameworks like Laravel/CodeIgniter is done, because once I was able to grasp your lessons, I want to jump in to Laravel, so what I mean is I want to use your Lesson as a key in order for me to start learning Larave

Ответить
@shaikhanuman8012
@shaikhanuman8012 - 18.08.2020 09:54

very good information tq for provoding great lectures. keep move on always providing good content.

Ответить
@dccastro2182
@dccastro2182 - 04.08.2020 13:14

Thanks for video !! I'm feeling so profissional with your tutorials 😁😁😁!!
.

Ответить
@murunwascengy2762
@murunwascengy2762 - 04.08.2020 11:32

Thank you again for very informative tutorial 🥇🥇🥇

Ответить
@47Lancelot
@47Lancelot - 04.08.2020 03:24

Great lesson! Didn’t know this trick with converting array to string so PDO can eat an array like that :) php isn’t trendy but is still awesome tool

Ответить
@topalek
@topalek - 03.08.2020 22:39

Do you will implement a DI container for this project?

Ответить
@topalek
@topalek - 03.08.2020 22:26

at last. Maybe you will open the videos every day insted of one video in two days?

Ответить
@tojikacademy
@tojikacademy - 03.08.2020 19:08

very informative)

Ответить
@alisiraj2100
@alisiraj2100 - 03.08.2020 18:56

Thanx

Ответить
@rajabhishek2936
@rajabhishek2936 - 03.08.2020 18:23

Thank you so much for this amezing course.god bless you bro

Ответить
@BJK_kasva
@BJK_kasva - 03.08.2020 18:03

Thanks for video 😘

Ответить