Question
what is the meaning of LAMP and why do we need it in order to make the database working?
3. What is the meaning of LAMP and why do we need it in order to make the database working. tahanan ha? why it hecame clawar
0 0
Add a comment Improve this question Transcribed image text
Answer #1

LAMP (Linux, Apache, MySQL, PHP)

LAMP is an open source Web development platform that uses Linux as the operating system, Apache as the Web server, MySQL as the relational database management system and PHP as the object-oriented scripting language. (Sometimes Perl or Python is used instead of PHP.)

Because the platform has four layers, LAMP is sometimes referred to as a LAMP stack. Stacks can be built on different operating systems. Developers that use these tools with a Windows operating system instead of Linux are said to be using WAMP; with a Macintosh system, MAMP; and with a Solaris system, SAMP.

The LAMP platform consists of four components that are structured in a layered way. Each layer provides a critical part of the entire software stack:

  • Linux. Linux is the lowest-level layer and provides the operating system. Linux actually runs each of the other components. You are not specifically limited to Linux, however; you can easily run each of the other components on Microsoft®; Windows®;, Mac OS X, or UNIX® if you need to.
  • Apache. The next layer is Apache, the Web server. Apache provides the mechanics for getting a Web page to a user. Apache is a stable, mission-critical-capable server, and it runs more than 65 percent of all Web sites on the Internet. The PHP component actually sits inside Apache, and you use Apache and PHP together to create your dynamic pages.
  • MySQL. MySQL provides the data-storage side of the LAMP system. With MySQL, you have access to a very capable database suitable for running large and complex sites. Within your Web application, all your data, products, accounts, and other types of information will reside in this database in a format that you can easily query with the SQL language.
  • PHP. PHP is a simple and efficient programming language that provides the glue for all the other parts of the LAMP system. You use PHP to write dynamic content capable of accessing the data in the MySQL database and some of the features that Linux provides.

MySQL

If you are asking yourself what makes the information on the websites so well organized and dynamically generated as we browse through the separate web pages, executing various click, select, download, etc. actions, the answer is simple - the databases. A database is a structured collection of data. The content of the database can be anything from a cooking recipe to a image gallery or the vast amounts of information in a corporate network. To add, access, and process data stored in a computer database, you need a database management system. Since computers are very good at handling large amounts of data, database management systems play a central role in computing, as standalone utilities, or as parts of other applications. To add speed and flexibility, relational database management systems (RDBMS), such as MySQL, store data in separate tables rather than putting all the data in one big storeroom. Websites which use databases have many advantages. They provide structured, easily accessible and editable content, available to multiple users. Also because most of the information is stored in the database the content can be easily transferred or exported to another web application, new web server or a newer version of the latter.

Create the MySQL database

The phpMyAdmin client

Before you can create your Web application, you must first create the database where your customer information will reside. You will use this database to store the data, display it, and more. Ushering MySQL support into your application requires a few steps. First, you have to create a database as well as the data to go into it, which is where the phpMyAdmin client comes in.

The phpMyAdmin client provides a Web interface (see Figure 1) through which you can manage every aspect of a MySQL database, including managing users, creating databases, adding tables, inserting data, and creating relationships. SQL controls virtually every aspect of the MySQL database.

Figure 1. The phpMyAdmin Web interface
Mozilla Firefox 127.0.0.1 locallist phpMyAdmin 26 Eile Edit View Go Bookmarks Tools Help 4. http://127.0.0.1/phpmyadmin Firef

Create the MySQL database

When you have loaded and logged in to phpMyAdmin, perform the following steps to create your database:

  1. Type customer in the Create new database text box to create a database of that name, then click Create. The new database appears in the left panel.
  2. Create a new table by entering customerlist as the name of the table and 3 as the number of fields.

The design window appears in which you can configure the three fields in your table. Each field has several options across a row. In this table, you need to create the following fields:

  • id. This field provides a unique ID for each record in the table. It is always a good idea to have a unique field that you can use to identify a record. The easiest way to achieve this is by creating a numeric field called ID and ensuring that there is a different number for each record. MySQL can help you with this by automating the addition of a unique number.
  • forename. This field contains a forename for a customer in the table.
  • surname. This field contains the surname. I recommend keeping the first and last names separate, because the more abstract your data is, the greater the flexibility of your database. (For more information about data abstraction and referential integrity, see Related topics.)

Fill out the fields

Filling out these fields in phpMyAdmin is simple. Simply add the following information, starting with the top row:

  • In the first row, type id in the Field box, and set the Type to INT. Select auto_increment from the Extra drop-down list. (The auto_increment option sets MySQL to update the id field for you and adds a new number into the field each time you add a record.) Finally, select the PRIMARY KEY option at the end of the row to prevent MySQL from allowing a duplicate value in this field.
  • In the second row, type forename in the Field box, set the Type to VARCHAR, and set the Length to 20. In this field, you are setting the data type to that of a variable character to ensure that the field will be no longer than 20 characters but will take up only the right amount of memory as data is added.
  • The third row is identical to the second row, except it has surname in the Field box.

Click Save to create your table (see Figure 2).

Figure 2. Create your MySQL table
Montilla Firefo x 127.0.01 localhost customers customersist phpMyAdmin 26 Bile Edt View Go Bookmarks Tools Help hetp://127.0.

View the SQL output

An important point to note about phpMyAdmin is that whenever you perform any interactions in the interface, the SQL that was executed to perform the action is displayed to you. This behavior is a fantastic method of learning the nuts and bolts of SQL, so always make a point of observing this output to see what SQL command was used to perform your request. In the case of the table you just created, you get the following SQL:

Ž CREATE TABLE `customerslist ( id INT NOT NULL AUTO_INCREMENT, forename VARCHAR( 20 ) NOT NULL, surname VARCHAR( 20 ) NO


Now you have to add some data to the table you've created. To do so, click the Insert tab. The phpMyAdmin interface displays two forms in which you can add two records (see Figure 3). You don't actually need to add two records, but having two forms is handy when you need to add a lot of data. Fill in the forename and surname fields, and remember not to add anything to the id field; the auto_increment option ensures that this field is filled for you. Add several records to make your database appear full of customers.Add data to the table

Figure 3. Insert records in the database table
127.0.0.1 localhost customers >> customers phpMyAdmin 26.1.Mozilla Firefox Ele Edit View Go Bookmarks Tools Help . . http://1

When you have added the records, click the Browse tab to see the contents of your table, which looks similar to Figure 4.

Figure 4. Browse database records
Frelox 127.0.0.1 localhost customers customers is phpMyAdmin 2.6.1. Mox Ele Edit View Go Bookmarks Tools Help 4. a http://127

Access the database through PHP

Connect to MySQL in PHP

With a table created, you're set to roll up your collaborative sleeves and get MySQL hooked into PHP. The first step in performing this process is to make a connection to the MySQL server. When you have made the connection, you're ready to interact with the server.

To begin, create four following variables to contain the details about where the database is and how to connect to it. These variables are db_host, db_username, db_password, and db_database. Note that variables in PHP begin with a dollar sign ($):

$db_host = localhost; Sdb_username = bob; Sdb_password = sum65for!; Sdb_database = customers;


Perform the connection These four variables contain important information about your database connection. The first variable, $db_host, indicates where the MySQL server is located. (This location is probably localhost, unless you are running the server on a separate networked machine.) The $db_username and $db_password variables contain the authentication details for the connection (in this case, a user called bob with sum65for! for a password). Finally, you need to indicate which database on the MySQL server you want to deal with; $db_database specifies this database as the customers database.

Remember that at this point, you have not actually connected to the database; you have merely created some variables with the relevant information. To connect to the database, run the following two lines of code:

1 $db = mysql_connect($db_host, $db_username, $db_password); 21 mysql_select_db($db_database, $db);


Perform a queryThe first line actually creates the connection. It uses the mysql_connect function to pass the host, username, and password information from the variables to the server. The result of this connection is stored in the $db variable. In the second line of code, you then use the mysql_select_db function to indicate which database on the server you want to use. To do this, pass the $db_database variable, which contains your chosen database, and indicate the connection that you want to choose that database from ($db). When you have entered these two lines, you should have a successful connection.

With a successful connection created, the next step is actually to ask the database for some information so that you can use it in a useful way. In this project, you want to pull the customer information from the database and display it on the screen.

The first step in performing a query is to create the SQL. Underneath the database connection code that you just wrote, add the following line:

1| $sql = SELECT * FROM customers;;

In this line, you select all values from the customers table. You can read this command from left to right as such: Select (SELECT) all values (*) from (FROM) the customers table (customers) and then end the query (;). Again, at this point in the script, the query has not actually been executed: You have only put the SQL query into a variable. To actually send the query to the database, use the following command:

1| Sresult = mysql_query($sql);
In this command, you use the mysql_query function to send the $sql variable to the server. The result of this query (a collection of information containing the results from your query) is then made available in the $result variable. The actual data that is stored in the $result variable is called a Record Set, and it provides a container full of information with your results

Pull customers out of the database

So, how does all this array theory relate to getting the customer information out of the database? You use an array to store the details from each row, and store the data in a series of key-value pairs. This way, if you want to get the contents of the forename field, you look up the forename key in the array.

To iterate through each row in the record set, use the following example:

1 while ($row = mysql_fetch_assoc($result)) { echo $row[forename]. . $row[surname]; 313

You should see the output that Figure 5 shows for your records. Figure 5. Display the contents of the customers table Mozilla

Hope the answer is helpful
.

Add a comment
Know the answer?
Add Answer to:
what is the meaning of LAMP and why do we need it in order to make...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT