{"id":24308136,"url":"https://github.com/fulldecent/beginner-project-php-sql","last_synced_at":"2025-09-26T14:30:52.598Z","repository":{"id":147412952,"uuid":"119880723","full_name":"fulldecent/beginner-project-php-sql","owner":"fulldecent","description":"You will learn to create your first meaningful PHP project which connects to a database","archived":false,"fork":false,"pushed_at":"2019-10-17T01:32:28.000Z","size":11,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-17T04:52:04.962Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fulldecent.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["fulldecent"],"custom":["https://www.paypal.me/fulldecent","https://amazon.com/hz/wishlist/ls/EE78A23EEGQB"]}},"created_at":"2018-02-01T19:09:35.000Z","updated_at":"2021-03-15T20:29:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"217b76a9-ccc9-4155-9979-508cbce7e1cd","html_url":"https://github.com/fulldecent/beginner-project-php-sql","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fulldecent/beginner-project-php-sql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fulldecent%2Fbeginner-project-php-sql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fulldecent%2Fbeginner-project-php-sql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fulldecent%2Fbeginner-project-php-sql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fulldecent%2Fbeginner-project-php-sql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fulldecent","download_url":"https://codeload.github.com/fulldecent/beginner-project-php-sql/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fulldecent%2Fbeginner-project-php-sql/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":277090745,"owners_count":25759207,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-26T02:00:09.010Z","response_time":78,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-17T04:52:06.920Z","updated_at":"2025-09-26T14:30:52.589Z","avatar_url":"https://github.com/fulldecent.png","language":null,"funding_links":["https://github.com/sponsors/fulldecent","https://www.paypal.me/fulldecent","https://amazon.com/hz/wishlist/ls/EE78A23EEGQB"],"categories":[],"sub_categories":[],"readme":"# YOUR FIRST PHP+SQL DATABASE PROJECT\n\nYou will create a website that lists the all-time top 50 MLB players (by runs). An index page shows a list of these players, alphabetically by name. A separate page for each player shows fun statistics about that player.\n\n## PREREQUESITES\n\nYou must have a basic understanding of HTML for this project.\n\n## TECHNOLOGY STACK\n\nInstall PHP on your computer (you may already have it). Test that it works by creating a file: `index.php` containing `\u003c?php echo 'Hello World' ?\u003e` and then running `php -S localhost:8888` and opening a browser to [http://localhost:8888](http://localhost:8888).\n\nDownload this file [players.db](players.db).\n\nInstall SQLite on your computer (you may already have it). Test that it works by running `sqlite3 players.db .schema` which should print out the format of the data in the provided database (attached).\n\n## WORK PLAN\n\n**Create the view**\n\n- [ ] Create a simple page `ricky-henderson.html` that displays the following information:\n\n  | Name | Henderson, R |\n  | ---- | ------------ |\n  | Pos  | LF           |\n  | G    | 3081         |\n  | AB   | 10961        |\n  | R    | 2295         |\n  | H    | 3055         |\n  | 2B   | 510          |\n  | 3B   | 66           |\n  | HR   | 297          |\n  | RBI  | 1115         |\n  | BB   | 2190         |\n  | SO   | 1694         |\n  | SB   | 1406         |\n  | CS   | 335          |\n  | AVG  | 0.279        |\n  | OBP  | 0.401        |\n  | SLG  | 0.419        |\n  | OPS  | 0.82         |\n\n  - You can learn what these stats mean by hovering over the table headngs at http://mlb.mlb.com/stats\n  - Use Bootstrap or Bulma.\n\n- [ ] Create a simple page `index.html` which lists the name of five baseball players you like and each one of them links to `ricky-henderson.html`.\n\n- [ ] Rename `index.html` to `index.php` and `ricky-henderson.html` to `player.php`, keep your PHP server open so you can confirm these files still work.\n\n- [ ] Use this code as a \"mock\" for your database query of all player names. This represents the format of data you will get later. Figure out how to weave this into your current code so that the PHP code creates the HTML code you want.\n\n  ```php\n  \u003c?php\n  $playerNames = ['Henderson, R', 'Batty McBatson', 'Pitcher DeSusa'];\n  foreach ($playerNames as $playerName) {\n  ?\u003e\n    \n  \u003cp\u003eHERE IS A PLAYER: \u003c?php echo $playerName; ?\u003e \u003c/p\u003e\n  \n  \u003c?php\n  }\n  ?\u003e\n  ```\n\n- [ ] Use this code as a mock for your database query about player details. Add the data from above in this mock and use the method below to weave the information \"from the database\" into your HTML.\n\n  ```php\n  \u003c?php\n  $playerName = 'Henderson, R';\n  $playerDetails = ['Pos'=\u003e'LF'];\n  ?\u003e\n  \n  \u003cp\u003eTHE PLAYER NAME IS: \u003c?php echo $playerName; ?\u003e \u003c/p\u003e\n  \u003cp\u003eTHE PLAYER POSITION IS: \u003c?php echo $playerDetails['Pos']; ?\u003e \u003c/p\u003e\n  ```\n\n\n- [ ] Update `index.php` so that that the links go to like `player.php?player=Henderson, R`\n\n**Create the model**\n\n- [ ] Create a SQL query which extracts the names of all players in the provided database.\n\n  ```sh\n  # Hint: here's how you run a query, this one extract all data from the database\n  sqlite3 -header players.db 'SELECT * FROM players'\n  ```\n\n- [ ] Create a SQL query which returns all data for the player `Henderson, R`.\n\n**Create the controller**\n\n- [ ] Read https://phpdelusions.net/pdo sections \"Connecting. DSN\" and \"Running SELECT INSERT, UPDATE, or DELETE statements\" to understand best practices we will use here. Today we will use a SELECT query and `fetchAll()` to get data into the variable (see \"Getting a column\").\n- [ ] At the bottom of the `index.php` file, try to use the PHP Delusions technique, and the \"all player names\" query you developed to extract the data from the database into the variable `$playerNames`. \n- [ ] Use this code `\u003c?php var_dump($playerNames); ?\u003e ` in your code to inspect the contents of this variable.\n- [ ] Make changes as needed until your variable has a format similar to the mock database query of player names above.\n- [ ] Weave in this query to replace the mock.\n- [ ] Do the same thing on `player.php` to query the database about `$playerName` (which happens to be `Henderson, R` right now). This will also require using a query that includes a `?` in it and the `exec([...])` command.\n\n\n- [ ] Point your browser to `player.php?player=Henderson, R`, now we want the PHP page to extract that name. Here's how you do that*:\n\n  ```php\n  \u003cp\u003eYou are searching for: \u003c?php echo $_GET['player'] ; ?\u003e \u003c/p\u003e\n  ```\n\n  *There is a security vulnerability in this example. You can ignore it for now. The solution is to use `htmlspecialchars()`.* \n\n- [ ] Use the code `$playerName = $_GET['player']` to connect the name you are querying (in the `?player=…` part of the URL) with the query that selects data from the database.\n\n## YOU'RE DONE\n\nReview the things you have learned today: creating a dynamic web page, reading data from a database, and connecting the web page to the database so that your visitors can get various information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffulldecent%2Fbeginner-project-php-sql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffulldecent%2Fbeginner-project-php-sql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffulldecent%2Fbeginner-project-php-sql/lists"}