Basic php mysql tutorial pdf




















We just launched W3Schools videos. Get certified by completing a course today! If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:. Report Error. Your message has been sent to W3Schools.

W3Schools is optimized for learning and training. PHP Projects. How to Check Whether Checkbox is checked or not using Javascript. Online Library Management System. Online Shopping Portal Project. Job Portal Project. Student Record System In php. Skip to content Web Development View Demo. Size: 2. Version: V 1. Download Now! How to send email from localhost using PHP March 31, December 2, at pm. Anuj Kumar says:. December 3, at am. With a database you can group different parts of your business into separate tables to help store your information logically.

Example tables might be: Employees, Supervisors, and Customers. Each table would then contain columns specific to these three areas.

To help store information related to each employee, the Employees table might have the following columns: Hire, Date, Position, Age, and Salary. If you are unsure, please contact your web host. Although you can set up MySQL manually on your home PC, it can be rather difficult for a beginner to do, and would require more than a few lessons!

If you think you've got what it takes, or you're just mentally unstable, head on over to MySQL. This tutorial assumes that you are using the most popular, CPanel. First, find the link that allows you to administer MySQL. Once there, you will need to do the following before you can start using MySQL. Create a new database. Create a new user with password.

Assign the user to the database If you have problems with this steps, seek help from your web hosting provider or ask a question in the Tizag Forums. Helpful Tool - phpMyAdmin! Also supplied by most hosting services is phpMyAdmin you can also install it anywhere you want, as it's open source and free.

This tool will allow you to view all the MySQL database, tables, and entries, as well as perform SQL queries remotely through a web browser. It's easy-to-use interface will allow you to do many common MySQL tasks quickly and easily, saving you many beginner headaches and helping you understand what's going on in a more visual manner.

If you already have that base covered feel free to skip on to the next lesson. Type the keyword "cmd" into the text field and press Enter to launch Window's command line interface.

The most popular options include:. MySQL Administrator This tool comes from the creators of MySQL, so you can be assured they have a solid understanding of database optimization and stability for power users. A brief overview of their product Navicat Admin can be found on their website.

Very few special characters and symbols are required to create a MySQL query, and most queries consist entirely of English words! Because this tutorial focuses on the combination of MySQL and PHP, most of the examples are ready for you to copy, paste, and run on your web server. This helps draw them out from the rest of the code and makes them much easier to read.

Capitalizing them allows you to tell from a quick glance that this query selects data from a table. Do not worry if it takes you more than a week to finish this tutorial. If you take the time to progress slowly, you will be much more well-informed about the MySQL database system than if you rushed through it in one sitting. Rather a MySQL database is a way of organizing a group of tables. If you were going to create a bunch of different tables that shared a common theme, you would group them into one database to make the management process easier.

Create a database and assign a new user to this database. For all of our beginning examples we will be using the following information:. Server - localhost. Database - test. Table - example. Username - admin.

Password - 1admin Note: The table may change in the advanced lessons, but everything else will remain the same! The server is the name of the server we want to connect to. Because all of our scripts are going to be placed on the server where MySQL is located the correct address is localhost.

If the MySQL server was on a different machine from where the script was running, then you would need to enter the correct url ask your web host for specifics on this.

Your database, table, username, and password do not have to match ours. If you choose a different set of login information, remember to insert your own information when copying the scripts in this tutorial.

Status Check So far, you should have created a new database and assigned a user to it. You should not have created a table yet. If you are up-to-date, then continue the tutorial. We will be making our first table in an upcoming lesson. This is done with the MySQL connect function. MySQL localhost If you've been around the internet a while, you'll know that IP addresses are used as identifiers for computers and web servers. In this example of a connection script, we assume that the MySQL service is running on the same machine as the script.

Please contact your web host for more details if localhost does not work. Server, username, and password. In our example above these arguments were:. Password - 1admin The "or die mysql Double-check your username, password, or server if you receive this error. Choosing the Working Database After establishing a MySQL connection with the code above, you then need to choose which database you will be using with this connection.

If you are up-to-date then continue the tutorial. We will be making our first table in the next lesson. In MySQL and other database systems, the goal is to store information in an orderly fashion. The table gets this done by making the table up of columns and rows. The columns specify what the data is going to be, while the rows contain the actual data.

Below is how you could imagine a MySQL table. This table has three categories, or "columns", of data: Name, Age, and Weight. This table has four entries, or in other words, four rows. Create Table MySQL Before you can enter data rows into a table, you must first define what kinds of data will be stored columns. We are now going to design a MySQL query to summon our table from database land. In future lessons we will be using this table, so be sure to enter this query correctly!

That's a lot of code all at once! Let's get down in the dirt and figure this stuff out. We will be going through the code line by line.

The two capitalized words are reserved MySQL keywords. Clear names will ensure that you will know what the table is about when revisiting it a year after you make it. The column "id" is not something that we need to worry about after we create this table, as it is all automatically calculated within MySQL. INT - This stands for integer or whole number. This means that no two ids can be the same, or else we will run into trouble.

This is why we made "id" an auto-incrementing counter in the previous line of code. It's "variable" because it can adjust its size to store as little as 0 characters and up to a specified maximum number of characters. We will most likely only be using this name column to store characters A-Z, a-z.

The number inside the parentheses sets the maximum number of characters. In this case, the max is Notice that there are no parentheses following "INT".

MySQL already knows what to do with an integer. The possible integer values that can be stored in an "INT" are -2,,, to 2,,,, which is more than enough to store someone's age! Your Homework Using the MySQL administration tool that your web host has, check to see if the table was created correctly.

Afterwards, try creating a few of your own, with PHP or with a MySQL administration tool, to be sure that you have gotten the hang of it. When inserting data it is important to remember the exact names and types of the table's columns. If you try to place a word essay into a column that only accepts integers of size three, you will end up with a nasty error! Inserting Data Into Your Table Now that you have created your table, let's put some data into that puppy! This code is much simpler to understand than the create table code, as will be most of the MySQL queries you will learn in the rest of this tutorial.

Once again, we will cover the code line by line. The name of the table we specified to insert data into was "example". Here we enter the name Timmy Mellowman for "name", and 23 for "age". Be sure to use your MySQL administration program provided by your web host to ensure that the data was inserted into your table correctly. Be careful not to run this script more than once, otherwise you will be inserting the same people, multiple times. This is called inserting duplicate records and is usually avoided.

We have already created a new table and inserted data into that table. In this lesson we will cover the most common MySQL Query that is used to retrieve information from a database.

If you wanted to copy some information in a document, you would first select the desired information, then copy and paste. In this example, we will output the first entry of our MySQL "examples" table to the web browser.

Below is a step-by-step walkthrough of the code. In English, this line of code reads "Select every entry from the table example". In our MySQL table "example," there are only two fields that we care about: name and age. These names are the keys to extracting the data from our associative array. In the next lesson we will see how to retrieve every entry of a table and put it into a nicely formatted table.



0コメント

  • 1000 / 1000