title
PHP REST API From Scratch [1] - Database & Read

description
In this series we will put together a REST API using PHP with NO FRAMEWORK. We will use object oriented programming along with PDO to connect and query a MySQL database. Code: https://github.com/bradtraversy/php_rest_myblog 💖 Become a Patron: Show support & get perks! http://www.patreon.com/traversymedia Website & Udemy Courses http://www.traversymedia.com Follow Traversy Media: http://www.facebook.com/traversymedia http://www.twitter.com/traversymedia http://www.instagram.com/traversymedia

detail
{'title': 'PHP REST API From Scratch [1] - Database & Read', 'heatmap': [{'end': 1249.677, 'start': 1199.452, 'weight': 0.858}, {'end': 1850.023, 'start': 1784.203, 'weight': 1}], 'summary': 'This tutorial series focuses on creating a rest api using pure php without frameworks, setting up postman for api testing, creating a php rest api and database class, using php methods and sql queries, and demonstrating data structuring and json creation in php.', 'chapters': [{'end': 153.454, 'segs': [{'end': 30.732, 'src': 'embed', 'start': 7.492, 'weight': 2, 'content': [{'end': 15.459, 'text': "Hey, what's going on, guys? So I recently had a couple of people ask me why I stopped doing PHP videos on my channel, and I definitely have not.", 'start': 7.492, 'duration': 7.967}, {'end': 25.067, 'text': "I just tend to focus more on front and back in JavaScript, because that's really my personal first choice when it comes to web development,", 'start': 16.36, 'duration': 8.707}, {'end': 27.229, 'text': 'mostly because of the full stack capabilities.', 'start': 25.067, 'duration': 2.162}, {'end': 30.732, 'text': 'And I really love JavaScript, but I also do love PHP.', 'start': 27.93, 'duration': 2.802}], 'summary': 'The speaker focuses on javascript for web development due to its full stack capabilities, despite still having a love for php.', 'duration': 23.24, 'max_score': 7.492, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OEWXbpUMODk/pics/OEWXbpUMODk7492.jpg'}, {'end': 165.821, 'src': 'embed', 'start': 133.121, 'weight': 0, 'content': [{'end': 136.985, 'text': 'so those are some, i guess, prerequisites to to this, this series.', 'start': 133.121, 'duration': 3.864}, {'end': 143.933, 'text': "if, if, um if you're interested and you really don't think you're ready for something like this, not that this is super advanced,", 'start': 136.985, 'duration': 6.948}, {'end': 151.501, 'text': "but it's it's definitely not like beginner based and i'm not going to explain every little thing like what, what a function does and all that stuff.", 'start': 143.933, 'duration': 7.568}, {'end': 153.454, 'text': "All right, so let's get into it.", 'start': 152.073, 'duration': 1.381}, {'end': 154.655, 'text': "I'm already talking too much.", 'start': 153.494, 'duration': 1.161}, {'end': 165.821, 'text': "I'm using Postman for my HTTP client basically to connect to my API and make post requests, get requests and all that stuff.", 'start': 155.275, 'duration': 10.546}], 'summary': 'Introduction to using postman for making http requests to api.', 'duration': 32.7, 'max_score': 133.121, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OEWXbpUMODk/pics/OEWXbpUMODk133121.jpg'}], 'start': 7.492, 'title': 'Creating a rest api with pure php', 'summary': 'Discusses creating a rest api using pure php without frameworks, focusing on front and back in javascript, and utilizing object-oriented concepts and pdo for mysql connection.', 'chapters': [{'end': 153.454, 'start': 7.492, 'title': 'Creating a rest api with pure php', 'summary': 'Discusses the decision to focus on front and back in javascript, the plan to create a rest api using pure php without frameworks, and the intention to use object-oriented concepts and pdo for connecting to a mysql database.', 'duration': 145.962, 'highlights': ['The decision to focus more on front and back in JavaScript due to personal preference and full stack capabilities, while still acknowledging the practicality and relevance of PHP in web development.', 'The plan to create a REST API using pure PHP without frameworks, with the understanding that it may take longer than using a framework but can help in learning more about the language and object-oriented concepts.', 'The intention to use object-oriented concepts and PDO for connecting to a MySQL database, with references to prerequisite knowledge available in other videos such as a PDO crash course and a 20-video series on PHP basics.']}], 'duration': 145.962, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OEWXbpUMODk/pics/OEWXbpUMODk7492.jpg', 'highlights': ['The plan to create a REST API using pure PHP without frameworks, with the understanding that it may take longer than using a framework but can help in learning more about the language and object-oriented concepts.', 'The intention to use object-oriented concepts and PDO for connecting to a MySQL database, with references to prerequisite knowledge available in other videos such as a PDO crash course and a 20-video series on PHP basics.', 'The decision to focus more on front and back in JavaScript due to personal preference and full stack capabilities, while still acknowledging the practicality and relevance of PHP in web development.']}, {'end': 311.275, 'segs': [{'end': 184.535, 'src': 'embed', 'start': 153.494, 'weight': 2, 'content': [{'end': 154.655, 'text': "I'm already talking too much.", 'start': 153.494, 'duration': 1.161}, {'end': 165.821, 'text': "I'm using Postman for my HTTP client basically to connect to my API and make post requests, get requests and all that stuff.", 'start': 155.275, 'duration': 10.546}, {'end': 171.565, 'text': 'So I would suggest downloading that from getpostman.com unless you use something else.', 'start': 166.242, 'duration': 5.323}, {'end': 177.328, 'text': 'If you want to get really technical and use something like curl or some command line tool.', 'start': 171.805, 'duration': 5.523}, {'end': 181.751, 'text': 'I know VS Code also has some rest client extensions.', 'start': 177.869, 'duration': 3.882}, {'end': 184.535, 'text': 'So whatever you want to use, but I would suggest Postman.', 'start': 182.131, 'duration': 2.404}], 'summary': 'Using postman to make http requests, suggested for api testing and connectivity.', 'duration': 31.041, 'max_score': 153.494, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OEWXbpUMODk/pics/OEWXbpUMODk153494.jpg'}, {'end': 232.644, 'src': 'embed', 'start': 204.077, 'weight': 0, 'content': [{'end': 209.639, 'text': "so i'm going to go to php, my admin, which, if you're using xamp, it's already included.", 'start': 204.077, 'duration': 5.562}, {'end': 217.961, 'text': "if you're using like, i don't know, vagrant or docker or something, you can get that installed or you can just use the, the sql shell,", 'start': 209.639, 'duration': 8.322}, {'end': 219.842, 'text': 'whatever you want to use to import this.', 'start': 217.961, 'duration': 1.881}, {'end': 223.263, 'text': 'now what you want to do is go to the github repository.', 'start': 220.462, 'duration': 2.801}, {'end': 226.343, 'text': "that's in the description and you'll see a file in there.", 'start': 223.263, 'duration': 3.08}, {'end': 232.644, 'text': "just you know, you can clone that repository or download it and there's a file called myblog.sql,", 'start': 226.343, 'duration': 6.301}], 'summary': 'Guide to import myblog.sql from github repository for phpmyadmin', 'duration': 28.567, 'max_score': 204.077, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OEWXbpUMODk/pics/OEWXbpUMODk204077.jpg'}, {'end': 289.672, 'src': 'embed', 'start': 250.566, 'weight': 1, 'content': [{'end': 254.927, 'text': "And then, if we look at our structure here, you'll see we have a post table and a categories table.", 'start': 250.566, 'duration': 4.361}, {'end': 256.528, 'text': 'And just to show you real quick,', 'start': 254.947, 'duration': 1.581}, {'end': 270.232, 'text': 'just in case you are creating this stuff manually the structure we have an ID in our posts which is the primary key auto increment category ID which is going to represent the whatever category this post is.', 'start': 256.528, 'duration': 13.704}, {'end': 277.72, 'text': "title, body, author and created at which is a date time field and it's the current timestamp.", 'start': 270.772, 'duration': 6.948}, {'end': 279.562, 'text': 'So this will automatically get filled.', 'start': 277.74, 'duration': 1.822}, {'end': 282.905, 'text': "We're not going to have to actually add this in our query.", 'start': 280.442, 'duration': 2.463}, {'end': 289.672, 'text': 'And then we have some data, so just some posts with some category IDs, a body, author, created at.', 'start': 283.506, 'duration': 6.166}], 'summary': 'The database has a post table and a categories table, with fields including id, category id, title, body, author, and created at.', 'duration': 39.106, 'max_score': 250.566, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OEWXbpUMODk/pics/OEWXbpUMODk250566.jpg'}], 'start': 153.494, 'title': 'Setting up postman for api testing', 'summary': 'Covers setting up postman for making http requests, utilizing xampp for environment setup, importing data to a database from a github repository, and explaining the structure of the post and categories tables.', 'chapters': [{'end': 311.275, 'start': 153.494, 'title': 'Setting up postman for api testing', 'summary': 'Discusses setting up postman for making http requests, using xampp for environment setup, importing data to a database from a github repository, and describing the structure of the post and categories tables.', 'duration': 157.781, 'highlights': ['The chapter discusses setting up Postman for making HTTP requests, using XAMPP for environment setup, importing data to a database from a GitHub repository, and describing the structure of the post and categories tables. This is the overall summary of the chapter, covering the main points and activities discussed.', 'XAMPP includes Apache, MariaDB (similar to MySQL), and PHP, with phpMyAdmin for database management. Provides information about the components included in XAMPP environment.', 'Importing myblog.sql file into a new database using phpMyAdmin. Describes the process of importing data to a database from a GitHub repository.', 'Describing the structure of the post and categories tables, including the fields and sample data. Details the structure and content of the post and categories tables, providing an understanding of the data to be worked with.']}], 'duration': 157.781, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OEWXbpUMODk/pics/OEWXbpUMODk153494.jpg', 'highlights': ['Covers setting up Postman for making HTTP requests, using XAMPP for environment setup, importing data to a database from a GitHub repository, and explaining the structure of the post and categories tables.', 'XAMPP includes Apache, MariaDB (similar to MySQL), and PHP, with phpMyAdmin for database management. Provides information about the components included in XAMPP environment.', 'Importing myblog.sql file into a new database using phpMyAdmin. Describes the process of importing data to a database from a GitHub repository.', 'Describing the structure of the post and categories tables, including the fields and sample data. Details the structure and content of the post and categories tables, providing an understanding of the data to be worked with.']}, {'end': 650.366, 'segs': [{'end': 391.445, 'src': 'embed', 'start': 350.003, 'weight': 4, 'content': [{'end': 353.146, 'text': "You can call it whatever you want, but this is what I'll have it in GitHub as.", 'start': 350.003, 'duration': 3.143}, {'end': 355.749, 'text': "So I'm going to open this with my text editor.", 'start': 353.747, 'duration': 2.002}, {'end': 359.914, 'text': "I'm using VS Code, which I highly recommend, but of course you can use whatever you want.", 'start': 355.769, 'duration': 4.145}, {'end': 365.183, 'text': 'Now as far as our file structure we basically have three different parts.', 'start': 360.819, 'duration': 4.364}, {'end': 374.031, 'text': "We're going to have our config folder that's going to hold our database class which is going to be used to do our core connection to MySQL using PDO.", 'start': 365.303, 'duration': 8.728}, {'end': 380.558, 'text': "Then we're going to have a models folder that will have our post post model and category model.", 'start': 374.532, 'duration': 6.026}, {'end': 391.445, 'text': "And then we're going to have our front end facing API folder where That'll have the files that we actually hit in the HTTP client in Postman.", 'start': 381.298, 'duration': 10.147}], 'summary': 'Setting up file structure with 3 parts for database and api.', 'duration': 41.442, 'max_score': 350.003, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OEWXbpUMODk/pics/OEWXbpUMODk350003.jpg'}, {'end': 442.443, 'src': 'embed', 'start': 415.874, 'weight': 0, 'content': [{'end': 421.395, 'text': "So let's put in our PHP tag and create a class called database.", 'start': 415.874, 'duration': 5.521}, {'end': 429.816, 'text': 'So this class is going to have some properties which are basically going to be our database parameters to connect.', 'start': 423.815, 'duration': 6.001}, {'end': 433.697, 'text': 'So these are going to be private, meaning they can only be accessed in this class.', 'start': 429.936, 'duration': 3.761}, {'end': 438.34, 'text': "So we'll have a host which is going to be localhost.", 'start': 434.237, 'duration': 4.103}, {'end': 442.443, 'text': "We're going to have a database name.", 'start': 439.801, 'duration': 2.642}], 'summary': 'Creating a php class called database with private properties for database parameters like host (localhost) and database name.', 'duration': 26.569, 'max_score': 415.874, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OEWXbpUMODk/pics/OEWXbpUMODk415874.jpg'}, {'end': 555.523, 'src': 'embed', 'start': 519.26, 'weight': 2, 'content': [{'end': 521.881, 'text': "So I'm going to actually put this in a try catch block.", 'start': 519.26, 'duration': 2.621}, {'end': 531, 'text': "We're going to say try catch, and inside catch we're going to put a parameter here.", 'start': 522.813, 'duration': 8.187}, {'end': 535.704, 'text': "It's going to be PDO exception, which will be a variable.", 'start': 531.04, 'duration': 4.664}, {'end': 537.365, 'text': 'You could call this anything.', 'start': 535.764, 'duration': 1.601}, {'end': 539.367, 'text': "We're going to call it E.", 'start': 537.385, 'duration': 1.982}, {'end': 541.688, 'text': 'Then in the catch.', 'start': 539.367, 'duration': 2.321}, {'end': 543.95, 'text': "basically, if something goes wrong, if there's an error,", 'start': 541.688, 'duration': 2.262}, {'end': 555.523, 'text': "we're just connection error and let's concatenate on and we can take that exception variable and it has a method called get message,", 'start': 543.95, 'duration': 11.573}], 'summary': 'Using try-catch block to handle pdo exception in php code.', 'duration': 36.263, 'max_score': 519.26, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OEWXbpUMODk/pics/OEWXbpUMODk519260.jpg'}], 'start': 311.275, 'title': 'Setting up a php rest api and database class', 'summary': 'Covers setting up a php rest api with a new folder in the server root and a file structure, creating a project structure with a config folder, models folder, and front-end facing api folder, and creating a database class with properties for database parameters. it also details creating a method to connect to a database, establishing a pdo connection, handling errors, and utilizing object-oriented principles.', 'chapters': [{'end': 365.183, 'start': 311.275, 'title': 'Setting up php rest api', 'summary': 'Discusses setting up a php rest api by creating a new folder in the server root, opening it with a text editor like vs code, and having a file structure with three different parts.', 'duration': 53.908, 'highlights': ["Creating a new folder in the server root The speaker mentions creating a new folder in the server root called 'php_rest_my_blog' and the importance of having a clear file structure.", 'Opening the folder with a text editor like VS Code The speaker recommends using VS Code as a text editor for opening the created folder, emphasizing its high suitability for the task.', 'Having a file structure with three different parts The speaker explains the necessity of having a file structure with three distinct parts while setting up the PHP REST API.']}, {'end': 473.943, 'start': 365.303, 'title': 'Setting up project structure and creating database class', 'summary': 'Outlines the creation of a project structure consisting of a config folder, a models folder, and a front-end facing api folder, and details the process of creating a database class with properties for database parameters.', 'duration': 108.64, 'highlights': ['The chapter outlines the creation of a project structure consisting of a config folder, a models folder, and a front-end facing API folder.', 'The database class is created with properties for database parameters including host, database name, username, password, and connection representation.']}, {'end': 650.366, 'start': 473.963, 'title': 'Creating a method to connect to a database', 'summary': "Discusses creating a public function 'connect' to establish a pdo connection to a database in php, handling potential errors using try-catch block, and utilizing object-oriented principles for setting properties and accessing them.", 'duration': 176.403, 'highlights': ["The chapter explains creating a public function 'connect' to set up a PDO connection to a database in PHP, emphasizing the use of object-oriented principles and setting the connection property to null.", "It discusses utilizing a try-catch block to handle potential errors, with the catch block concatenating the connection error message using the 'getMessage' method of the exception variable.", 'The chapter further details the process of connecting through PDO, including creating a new PDO object and passing in necessary parameters such as database type, host, database name, username, and password.']}], 'duration': 339.091, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OEWXbpUMODk/pics/OEWXbpUMODk311275.jpg', 'highlights': ["Creating a new folder in the server root called 'php_rest_my_blog' and emphasizing the importance of clear file structure", 'Outlining the creation of a project structure with a config folder, models folder, and front-end facing API folder', 'Creating a database class with properties for database parameters including host, database name, username, password, and connection representation', "Explaining the creation of a public function 'connect' to set up a PDO connection to a database in PHP, emphasizing the use of object-oriented principles", 'Detailing the process of connecting through PDO, including creating a new PDO object and passing in necessary parameters such as database type, host, database name, username, and password', "Utilizing a try-catch block to handle potential errors, with the catch block concatenating the connection error message using the 'getMessage' method of the exception variable"]}, {'end': 850.563, 'segs': [{'end': 813.405, 'src': 'embed', 'start': 718.401, 'weight': 0, 'content': [{'end': 720.842, 'text': 'Oh, and we also need to return the connection.', 'start': 718.401, 'duration': 2.441}, {'end': 726.985, 'text': "So under the try catch, we're just going to return this con.", 'start': 720.922, 'duration': 6.063}, {'end': 728.106, 'text': "And that's it.", 'start': 727.605, 'duration': 0.501}, {'end': 729.486, 'text': "That's our database class.", 'start': 728.166, 'duration': 1.32}, {'end': 732.308, 'text': "And that's what we'll use in our model.", 'start': 730.087, 'duration': 2.221}, {'end': 733.268, 'text': "So let's save this.", 'start': 732.348, 'duration': 0.92}, {'end': 735.489, 'text': "And that's it.", 'start': 734.969, 'duration': 0.52}, {'end': 736.37, 'text': 'We can close that up.', 'start': 735.529, 'duration': 0.841}, {'end': 740.555, 'text': "So next thing we're going to do is create another folder called Models.", 'start': 737.714, 'duration': 2.841}, {'end': 743.536, 'text': 'This should not be in the config.', 'start': 741.915, 'duration': 1.621}, {'end': 745.837, 'text': "Didn't mean to do that.", 'start': 744.897, 'duration': 0.94}, {'end': 757.181, 'text': "Okay, so in Models, let's create a new file called post.php.", 'start': 745.857, 'duration': 11.324}, {'end': 760.542, 'text': 'And this is going to be a class.', 'start': 758.321, 'duration': 2.221}, {'end': 764.884, 'text': "So just like we did with database, we're going to say class.", 'start': 761.002, 'duration': 3.882}, {'end': 768.135, 'text': "And we're going to call it post.", 'start': 766.914, 'duration': 1.221}, {'end': 772.238, 'text': 'And we want to do some DB stuff here.', 'start': 770.176, 'duration': 2.062}, {'end': 780.083, 'text': 'So we want a private property of CNN representing our connection.', 'start': 773.539, 'duration': 6.544}, {'end': 786.187, 'text': 'And then we want our table for this model, which is going to be posts.', 'start': 780.703, 'duration': 5.484}, {'end': 788.669, 'text': 'All right.', 'start': 788.429, 'duration': 0.24}, {'end': 790.05, 'text': "Then we'll set our properties.", 'start': 788.709, 'duration': 1.341}, {'end': 795.554, 'text': "I mean, they're all properties, but these are, I guess, our post properties.", 'start': 791.291, 'duration': 4.263}, {'end': 799.316, 'text': "So like the ID, and I'm going to set these to public.", 'start': 796.394, 'duration': 2.922}, {'end': 803.379, 'text': "So ID, we're not going to set them to any value.", 'start': 800.297, 'duration': 3.082}, {'end': 806.52, 'text': "We're just basically initializing them.", 'start': 803.419, 'duration': 3.101}, {'end': 813.405, 'text': "So let's say public category, underscore ID, public.", 'start': 807.481, 'duration': 5.924}], 'summary': 'Creating database and model classes, setting properties for post model.', 'duration': 95.004, 'max_score': 718.401, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OEWXbpUMODk/pics/OEWXbpUMODk718401.jpg'}], 'start': 650.406, 'title': 'Php pdo error mode and database class creation', 'summary': 'Covers setting error mode in php pdo to receive exceptions for better error handling and explains creating a database class with a connection return and a model class with properties representing post information.', 'chapters': [{'end': 717.08, 'start': 650.406, 'title': 'Setting error mode in php pdo', 'summary': 'Covers setting the error mode in php pdo to receive exceptions when making queries, ensuring better error handling and understanding of issues.', 'duration': 66.674, 'highlights': ['Setting error mode using PDO::setAttribute to PDO::ERRMODE_EXCEPTION ensures exceptions are thrown when queries encounter issues.', 'Understanding and setting error modes in PHP PDO can improve error handling and help in diagnosing issues more effectively.']}, {'end': 850.563, 'start': 718.401, 'title': 'Creating database class and models', 'summary': 'Explains the process of creating a database class with a connection return and a model class with properties representing post information including id, category, title, body, author, and creation date.', 'duration': 132.162, 'highlights': ['Creating a database class with a connection return The chapter discusses creating a database class with a return connection function, which will be used in the model.', "Defining a model class with post properties The process involves defining a model class 'post' with properties representing post information such as ID, category, title, body, author, and creation date.", 'Using a join in the query to retrieve category name In order to obtain the category name of the post, a join is used in the query to combine tables and retrieve the category name.']}], 'duration': 200.157, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OEWXbpUMODk/pics/OEWXbpUMODk650406.jpg', 'highlights': ['Setting error mode using PDO::setAttribute to PDO::ERRMODE_EXCEPTION ensures exceptions are thrown when queries encounter issues.', 'Understanding and setting error modes in PHP PDO can improve error handling and help in diagnosing issues more effectively.', 'Creating a database class with a connection return The chapter discusses creating a database class with a return connection function, which will be used in the model.', "Defining a model class with post properties The process involves defining a model class 'post' with properties representing post information such as ID, category, title, body, author, and creation date.", 'Using a join in the query to retrieve category name In order to obtain the category name of the post, a join is used in the query to combine tables and retrieve the category name.']}, {'end': 1303.617, 'segs': [{'end': 881.228, 'src': 'embed', 'start': 850.563, 'weight': 3, 'content': [{'end': 853.525, 'text': 'okay, so that should be all the fields that we want.', 'start': 850.563, 'duration': 2.962}, {'end': 860.97, 'text': "now we want to create a constructor all right now a constructor, we're going to say with dv.", 'start': 853.525, 'duration': 7.445}, {'end': 863.612, 'text': 'a constructor is basically a just a method.', 'start': 860.97, 'duration': 2.642}, {'end': 874.059, 'text': 'a method is a function within a class and a constructor is a method that runs automatically when you instantiate the class or when you instantiate an object from a class.', 'start': 863.612, 'duration': 10.447}, {'end': 881.228, 'text': "and to create this we're going to say public function and then double underscore construct.", 'start': 874.059, 'duration': 7.169}], 'summary': 'Creating a constructor in php with public function double underscore construct.', 'duration': 30.665, 'max_score': 850.563, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OEWXbpUMODk/pics/OEWXbpUMODk850563.jpg'}, {'end': 1094.796, 'src': 'embed', 'start': 1060.702, 'weight': 4, 'content': [{'end': 1063.285, 'text': 'So this is where we define C as categories.', 'start': 1060.702, 'duration': 2.583}, {'end': 1075.175, 'text': 'And we want to bring it in on where P category ID is equal to C dot ID.', 'start': 1063.765, 'duration': 11.41}, {'end': 1084.052, 'text': "So we're making a correlation here between the category ID field in the post table and the ID field in the category table.", 'start': 1076.37, 'duration': 7.682}, {'end': 1086.873, 'text': "So that's how we're going to be able to get this category name.", 'start': 1084.073, 'duration': 2.8}, {'end': 1094.796, 'text': "Because categories does have a name field, but we're saying get it as category name.", 'start': 1089.654, 'duration': 5.142}], 'summary': 'Defining correlation between post and category tables using category id and id fields.', 'duration': 34.094, 'max_score': 1060.702, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OEWXbpUMODk/pics/OEWXbpUMODk1060702.jpg'}, {'end': 1202.753, 'src': 'embed', 'start': 1171.612, 'weight': 0, 'content': [{'end': 1173.433, 'text': 'Okay, so this is PDO right here.', 'start': 1171.612, 'duration': 1.821}, {'end': 1176.475, 'text': 'So we want to prepare our query.', 'start': 1173.813, 'duration': 2.662}, {'end': 1182.207, 'text': "Okay, once we have that statement, we're just preparing it.", 'start': 1178.716, 'duration': 3.491}, {'end': 1184.508, 'text': "we haven't executed it yet, so that's what we want to do.", 'start': 1182.207, 'duration': 2.301}, {'end': 1195.011, 'text': 'next is we want to execute the query, and we can do that by saying stmt, and it has a method called execute,', 'start': 1184.508, 'duration': 10.503}, {'end': 1199.452, 'text': 'and then the last thing we want to do here is just return our statement.', 'start': 1195.011, 'duration': 4.441}, {'end': 1202.753, 'text': 'alright, so that is our read method.', 'start': 1199.452, 'duration': 3.301}], 'summary': 'Preparing and executing a query using pdo to create a read method.', 'duration': 31.141, 'max_score': 1171.612, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OEWXbpUMODk/pics/OEWXbpUMODk1171612.jpg'}, {'end': 1251.598, 'src': 'heatmap', 'start': 1199.452, 'weight': 1, 'content': [{'end': 1202.753, 'text': 'alright, so that is our read method.', 'start': 1199.452, 'duration': 3.301}, {'end': 1209.059, 'text': "hopefully I didn't make any mistakes, so we'll just save that Now.", 'start': 1202.753, 'duration': 6.306}, {'end': 1214.103, 'text': "I don't want to end this video yet, because I want us to actually have have some kind of result.", 'start': 1209.059, 'duration': 5.044}, {'end': 1218.507, 'text': 'So I want to be able to at least make a get request and get our data.', 'start': 1214.644, 'duration': 3.863}, {'end': 1226.713, 'text': "So now we're going to create our API folder, which is like kind of like just a front facing API that we're going to be able to access.", 'start': 1218.567, 'duration': 8.146}, {'end': 1229.996, 'text': "And let's create a folder in here called post.", 'start': 1227.594, 'duration': 2.402}, {'end': 1236.611, 'text': 'So anything to do with posts will go in here.', 'start': 1231.829, 'duration': 4.782}, {'end': 1239.552, 'text': "So I'm going to create a file called read.php.", 'start': 1236.651, 'duration': 2.901}, {'end': 1246.956, 'text': "So this file here, we're going to interact with the model.", 'start': 1241.853, 'duration': 5.103}, {'end': 1249.677, 'text': "So let's start off here.", 'start': 1247.836, 'duration': 1.841}, {'end': 1251.598, 'text': 'Of course, we need our PHP tags.', 'start': 1249.697, 'duration': 1.901}], 'summary': 'Creating api folder for accessing data with php read method.', 'duration': 33.031, 'max_score': 1199.452, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OEWXbpUMODk/pics/OEWXbpUMODk1199452.jpg'}], 'start': 850.563, 'title': 'Php methods, api creation, and sql queries', 'summary': 'Covers creating a php constructor and method for reading posts, as well as writing sql queries for joining tables, setting up a rest api, and using prepared statements with a focus on database initialization and response headers.', 'chapters': [{'end': 937.718, 'start': 850.563, 'title': 'Php constructor and method creation', 'summary': 'Covers creating a constructor in php, which is a method that runs automatically when instantiating a class, and creating a method to read posts, with a focus on setting up the constructor and initializing the database connection.', 'duration': 87.155, 'highlights': ['A constructor in PHP is a method that runs automatically when instantiating a class, and in this context, it involves setting the connection of a class to a database object.', "The process of creating a constructor involves using the 'public function' syntax followed by double underscore construct, and then passing in a database object when instantiating a new post.", 'Creating a method to read posts involves setting up a query and initializing the process of selecting data.']}, {'end': 1303.617, 'start': 937.998, 'title': 'Creating api and writing sql queries', 'summary': 'Covers writing sql queries for joining tables and creating an api using php, including explanations of left join, prepared statements, and setting response headers for a rest api.', 'duration': 365.619, 'highlights': ['The chapter covers writing SQL queries for joining tables The speaker explains the process of writing SQL queries for joining tables using aliases, selecting specific columns, defining table names, and using left joins.', 'Creating an API using PHP The chapter delves into creating a REST API using PHP, including setting response headers, such as access-control-allow-origin and content type, to allow public access and accept JSON.', 'Explanation of left join and prepared statements The speaker provides an explanation of left join in SQL to bring in additional tables and the use of prepared statements in PHP to execute the queries.']}], 'duration': 453.054, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OEWXbpUMODk/pics/OEWXbpUMODk850563.jpg', 'highlights': ['Creating a REST API using PHP, including setting response headers for public access and accepting JSON.', 'Writing SQL queries for joining tables using aliases, selecting specific columns, defining table names, and using left joins.', 'A constructor in PHP involves setting the connection of a class to a database object and runs automatically when instantiating a class.', "The process of creating a constructor involves using the 'public function' syntax followed by double underscore construct, and then passing in a database object when instantiating a new post.", 'The process of creating a method to read posts involves setting up a query and initializing the process of selecting data.', 'The speaker provides an explanation of left join in SQL to bring in additional tables and the use of prepared statements in PHP to execute the queries.']}, {'end': 1487.438, 'segs': [{'end': 1413.469, 'src': 'embed', 'start': 1386.669, 'weight': 0, 'content': [{'end': 1397.252, 'text': 'Now remember when we created our constructor in the post it takes in this DB and then it adds it to the connection so that we can go and we can do our stuff down here with our query.', 'start': 1386.669, 'duration': 10.583}, {'end': 1402.334, 'text': 'So we need to pass in that DB object like that.', 'start': 1397.813, 'duration': 4.521}, {'end': 1404.043, 'text': 'All right.', 'start': 1403.763, 'duration': 0.28}, {'end': 1409.246, 'text': 'Now, once we do that, we want to basically call our read method.', 'start': 1404.103, 'duration': 5.143}, {'end': 1413.469, 'text': 'OK, this right here, our read function inside the post class.', 'start': 1409.266, 'duration': 4.203}], 'summary': 'Constructor adds db to connection for querying, then calls read method.', 'duration': 26.8, 'max_score': 1386.669, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OEWXbpUMODk/pics/OEWXbpUMODk1386669.jpg'}], 'start': 1304.218, 'title': 'Database connection, object instantiation, post query, and row count', 'summary': 'Covers setting up a database connection, instantiating database and post objects, and calling the read method inside the post class for performing database operations. it also discusses creating a variable to store the result of a post query, obtaining the row count, and checking if there are any posts available, emphasizing the initialization of an array if posts are present.', 'chapters': [{'end': 1413.469, 'start': 1304.218, 'title': 'Setting up database connection and instantiating objects', 'summary': 'Discusses setting up a database connection, instantiating database and post objects, and calling the read method inside the post class for performing database operations.', 'duration': 109.251, 'highlights': ['The chapter covers bringing in the database and models, including the post model, and instantiating the database object for connection.', 'It explains the process of creating a variable for the database connection and instantiating the post object to perform database operations.', 'The chapter demonstrates how to call the read method inside the post class to execute database queries.']}, {'end': 1487.438, 'start': 1414.189, 'title': 'Post query and row count', 'summary': 'Discusses creating a variable to store the result of a post query, obtaining the row count, and checking if there are any posts available, emphasizing the initialization of an array if posts are present.', 'duration': 73.249, 'highlights': ['The chapter emphasizes creating a variable to store the result of a post query and obtaining the row count, which is crucial for further processing.', 'It discusses checking the row count to determine if there are any posts available, highlighting the conditional check for the presence of posts based on the row count being greater than zero.', "The chapter also stresses the importance of initializing an array if posts are present, showcasing the process of initializing the 'posts_ARR' array when posts are available."]}], 'duration': 183.22, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OEWXbpUMODk/pics/OEWXbpUMODk1304218.jpg', 'highlights': ['The chapter covers bringing in the database and models, including the post model, and instantiating the database object for connection.', 'It explains the process of creating a variable for the database connection and instantiating the post object to perform database operations.', 'The chapter demonstrates how to call the read method inside the post class to execute database queries.', 'The chapter emphasizes creating a variable to store the result of a post query and obtaining the row count, which is crucial for further processing.', 'It discusses checking the row count to determine if there are any posts available, highlighting the conditional check for the presence of posts based on the row count being greater than zero.', "The chapter also stresses the importance of initializing an array if posts are present, showcasing the process of initializing the 'posts_ARR' array when posts are available."]}, {'end': 1936.759, 'segs': [{'end': 1570.568, 'src': 'embed', 'start': 1511.551, 'weight': 0, 'content': [{'end': 1512.713, 'text': "I'm also going to do this.", 'start': 1511.551, 'duration': 1.162}, {'end': 1515.936, 'text': "I'm going to say post array.", 'start': 1512.753, 'duration': 3.183}, {'end': 1527.468, 'text': "We're going to take that post array we just created and then we're going to say data and set that also to an array.", 'start': 1516.016, 'duration': 11.452}, {'end': 1529.611, 'text': "That's where the actual data is going to go.", 'start': 1527.508, 'duration': 2.103}, {'end': 1540.361, 'text': 'So now this result is going to give us the result from the read function that we created.', 'start': 1530.515, 'duration': 9.846}, {'end': 1541.922, 'text': 'So we want to loop through that.', 'start': 1540.481, 'duration': 1.441}, {'end': 1544.724, 'text': "So to do that we'll create a while loop.", 'start': 1542.562, 'duration': 2.162}, {'end': 1554.81, 'text': "And inside here we're going to say while and then we're going to have a variable called row and set that to result.", 'start': 1548.786, 'duration': 6.024}, {'end': 1562.56, 'text': "fetch, and then remember we're using PDO, and we can fetch it as different things.", 'start': 1558.115, 'duration': 4.445}, {'end': 1564.862, 'text': 'I want to fetch it as an associative array.', 'start': 1562.62, 'duration': 2.242}, {'end': 1570.568, 'text': "So we're going to say PDO double underscore fetch underscore assoc.", 'start': 1564.882, 'duration': 5.686}], 'summary': 'Creating a while loop to fetch data as an associative array using pdo.', 'duration': 59.017, 'max_score': 1511.551, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OEWXbpUMODk/pics/OEWXbpUMODk1511551.jpg'}, {'end': 1633.393, 'src': 'embed', 'start': 1594.78, 'weight': 6, 'content': [{'end': 1609.165, 'text': "So what we can do is we can use extract and then pass in row and now we'll be able to use like title and body and stuff like that instead of that row.", 'start': 1594.78, 'duration': 14.385}, {'end': 1610.246, 'text': 'title, row, body.', 'start': 1609.165, 'duration': 1.081}, {'end': 1615.756, 'text': 'Alright, now we want to create a post item for each post.', 'start': 1611.212, 'duration': 4.544}, {'end': 1633.393, 'text': "so I'm going to say post item equals an array and inside here I'm going to say let's say, ID is going to be ID title.", 'start': 1615.756, 'duration': 17.637}], 'summary': 'Using extract to create post items with id and title', 'duration': 38.613, 'max_score': 1594.78, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OEWXbpUMODk/pics/OEWXbpUMODk1594780.jpg'}, {'end': 1753.223, 'src': 'embed', 'start': 1723.326, 'weight': 4, 'content': [{'end': 1736.797, 'text': 'and we want to take the posts underscore array and then the data value, And then what we want to push onto it is this post item.', 'start': 1723.326, 'duration': 13.471}, {'end': 1739.601, 'text': "And it's going to loop through each post and do this for each one.", 'start': 1736.857, 'duration': 2.744}, {'end': 1743.886, 'text': 'Now we want to go outside of the loop, which ends right here.', 'start': 1740.462, 'duration': 3.424}, {'end': 1753.223, 'text': "and we want to turn it to JSON because right now it's just a PHP array and we don't want that.", 'start': 1745.621, 'duration': 7.602}], 'summary': 'Loop through posts array, push post items, and convert to json.', 'duration': 29.897, 'max_score': 1723.326, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OEWXbpUMODk/pics/OEWXbpUMODk1723326.jpg'}, {'end': 1850.023, 'src': 'heatmap', 'start': 1784.203, 'weight': 1, 'content': [{'end': 1803.207, 'text': "We'll echo out JSON encode and we'll just put an array in here and say message and we'll set that to no posts found.", 'start': 1784.203, 'duration': 19.004}, {'end': 1805.033, 'text': 'All right.', 'start': 1804.673, 'duration': 0.36}, {'end': 1807.055, 'text': 'So that should do it.', 'start': 1805.854, 'duration': 1.201}, {'end': 1807.935, 'text': "Let's save this.", 'start': 1807.095, 'duration': 0.84}, {'end': 1811.557, 'text': 'And now we should be able to do this.', 'start': 1809.016, 'duration': 2.541}, {'end': 1812.878, 'text': 'We should be able to test it out.', 'start': 1811.597, 'duration': 1.281}, {'end': 1822.384, 'text': "So let's go to Postman and we're going to make a get request to HTTP local host slash.", 'start': 1812.938, 'duration': 9.446}, {'end': 1829.729, 'text': 'What the hell did I call this? PHP rests my blog.', 'start': 1823.625, 'duration': 6.104}, {'end': 1838.853, 'text': 'slash and then api slash and you could, if you want.', 'start': 1834.011, 'duration': 4.842}, {'end': 1841.274, 'text': 'you can map this to a host using your host file.', 'start': 1838.853, 'duration': 2.421}, {'end': 1850.023, 'text': "if you don't want to use like localhost slash something, you could map it to a local domain, but i'm not going to go through that API slash.", 'start': 1841.274, 'duration': 8.749}], 'summary': "Using json encode to display 'no posts found' message for rest api", 'duration': 65.82, 'max_score': 1784.203, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OEWXbpUMODk/pics/OEWXbpUMODk1784203.jpg'}], 'start': 1487.438, 'title': 'Php data structuring and json creation', 'summary': 'Covers data structuring in php using associative arrays, looping with a while loop, and creating json data. it also demonstrates testing the api using postman to retrieve a json object containing posts with various details.', 'chapters': [{'end': 1690.426, 'start': 1487.438, 'title': 'Data structuring and looping in php', 'summary': 'Covers structuring data in php using associative arrays and looping through the data using a while loop, with a focus on extracting and using the data efficiently.', 'duration': 202.988, 'highlights': ['Structuring data with a nested array for response The speaker discusses structuring the response to include a data value inside a nested array, allowing for additional elements like pagination and version info.', 'Looping through data using a while loop The chapter emphasizes the use of a while loop to iterate through the result from the read function, providing an efficient method for processing data.', "Using 'extract' to create variables from array data The use of 'extract' is demonstrated to create variables from the fetched associative array, enabling convenient access to data fields like title and body.", 'Applying HTML entity decode to body data The approach of using HTML entity decode on the body data is explained, ensuring proper handling of HTML content within the body field.', 'Creating a post item for each post The process of creating a post item array for each post, including fields like ID, title, body (decoded), author, category ID, and category name, is outlined.']}, {'end': 1936.759, 'start': 1690.426, 'title': 'Creating and outputting json data', 'summary': 'Covers creating a php method to push data into an array, converting the array to json, and outputting it, and demonstrates testing the api using postman to retrieve a json object containing posts with various details.', 'duration': 246.333, 'highlights': ['The chapter covers creating a PHP method to push data into an array. Demonstrates using PHP method array_push to add data to an array.', "Converting the array to JSON and outputting it. Utilizing PHP's JSON encode function to convert the posts array to a JSON object and output it.", 'Testing the API using Postman to retrieve a JSON object containing posts with various details. Shows the process of using Postman to make a get request and retrieve a JSON object containing posts with ID, title, body, author, category ID, and category name.']}], 'duration': 449.321, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/OEWXbpUMODk/pics/OEWXbpUMODk1487438.jpg', 'highlights': ['Looping through data using a while loop The chapter emphasizes the use of a while loop to iterate through the result from the read function, providing an efficient method for processing data.', 'Creating a post item for each post The process of creating a post item array for each post, including fields like ID, title, body (decoded), author, category ID, and category name, is outlined.', 'Testing the API using Postman to retrieve a JSON object containing posts with various details. Shows the process of using Postman to make a get request and retrieve a JSON object containing posts with ID, title, body, author, category ID, and category name.', 'Structuring data with a nested array for response The speaker discusses structuring the response to include a data value inside a nested array, allowing for additional elements like pagination and version info.', "Using 'extract' to create variables from array data The use of 'extract' is demonstrated to create variables from the fetched associative array, enabling convenient access to data fields like title and body.", 'Applying HTML entity decode to body data The approach of using HTML entity decode on the body data is explained, ensuring proper handling of HTML content within the body field.', 'The chapter covers creating a PHP method to push data into an array. Demonstrates using PHP method array_push to add data to an array.', "Converting the array to JSON and outputting it. Utilizing PHP's JSON encode function to convert the posts array to a JSON object and output it."]}], 'highlights': ['Creating a REST API using PHP, including setting response headers for public access and accepting JSON.', 'Writing SQL queries for joining tables using aliases, selecting specific columns, defining table names, and using left joins.', 'The plan to create a REST API using pure PHP without frameworks, with the understanding that it may take longer than using a framework but can help in learning more about the language and object-oriented concepts.', 'The intention to use object-oriented concepts and PDO for connecting to a MySQL database, with references to prerequisite knowledge available in other videos such as a PDO crash course and a 20-video series on PHP basics.', 'Covers setting up Postman for making HTTP requests, using XAMPP for environment setup, importing data to a database from a GitHub repository, and explaining the structure of the post and categories tables.', "Creating a new folder in the server root called 'php_rest_my_blog' and emphasizing the importance of clear file structure", 'Setting error mode using PDO::setAttribute to PDO::ERRMODE_EXCEPTION ensures exceptions are thrown when queries encounter issues.', 'Understanding and setting error modes in PHP PDO can improve error handling and help in diagnosing issues more effectively.', 'Creating a database class with a connection return The chapter discusses creating a database class with a return connection function, which will be used in the model.', "Defining a model class with post properties The process involves defining a model class 'post' with properties representing post information such as ID, category, title, body, author, and creation date.", 'The chapter covers bringing in the database and models, including the post model, and instantiating the database object for connection.', 'Looping through data using a while loop The chapter emphasizes the use of a while loop to iterate through the result from the read function, providing an efficient method for processing data.', 'Creating a post item for each post The process of creating a post item array for each post, including fields like ID, title, body (decoded), author, category ID, and category name, is outlined.', 'Testing the API using Postman to retrieve a JSON object containing posts with various details. Shows the process of using Postman to make a get request and retrieve a JSON object containing posts with ID, title, body, author, category ID, and category name.', 'Structuring data with a nested array for response The speaker discusses structuring the response to include a data value inside a nested array, allowing for additional elements like pagination and version info.', "Using 'extract' to create variables from array data The use of 'extract' is demonstrated to create variables from the fetched associative array, enabling convenient access to data fields like title and body.", 'Applying HTML entity decode to body data The approach of using HTML entity decode on the body data is explained, ensuring proper handling of HTML content within the body field.', 'The chapter covers creating a PHP method to push data into an array. Demonstrates using PHP method array_push to add data to an array.', "Converting the array to JSON and outputting it. Utilizing PHP's JSON encode function to convert the posts array to a JSON object and output it."]}