For enquiries call:
+1-469-442-0620
HomeBlogProgrammingWeb Development Using PHP And MySQL
PHP (or PHP Hypertext Preprocessor) is a server-side scripting language that is used to create dynamic web pages that can interact with databases. It is a widely-used open source language that is specifically used for web application development and can be embedded within HTML. In addition to the article on PHP & MySQL be sure to check out the important blog post on what is markdown.
The distinguishing feature of PHP is that the scripting code is executed on the server, which generates HTML that is sent back to the client. The client receives the result of executing the script without knowing the underlying code. Developers can configure the web server to process all the HTML files (containing the PHP script).
PHP course is easy to learn for any newcomer, but also offers advanced programming features.
PHP, as a scripting language, is popular among web developers because of its ability to interact with database systems including Oracle and MySQL.
This article discusses the use of PHP scripting language with the MySQL database. Any website can require a variety of data or information to display and to retrieve them from the database. This can include display of a simple list to the running of the website based on data stored in the database.
Listed below are some examples where PHP and MySQL can be used together:
Get to know more on microservices interview questions.
The procedure of setting up the MySQL database varies according to the host. Every database would require a user name and password, in order to access the database.
Database administration can be done using PHP scripts or using a program like PHPMyAdmin.
The next step is to create the database tables for storing the website information. Creating a database table using PHPMyAdmin is also simple. Alternatively, one can create and configure the entire database using the following PHP script:
CREATE TABLE tablename { Fields } Where the Fields are coded as fieldname type(length) extra_info Example: first varchar(15) NOT NULL
The following command is used in the PHP script to connect to the MySQL database:
mysql_connect(localhost,$username,$password);
where:
After configuring and connecting to the MySQL database, you can start executing PHP commands on the server.
Following are the 2 methods of executing a PHP command:
Mysql_query($query)
This form of command can be used to repeat the command simply by changing the variable.
Inserting data using PHP is identical to the procedure of data input using HTML pages. The advantage of using PHP is that the script does not need to be changed for each new piece of input data. Users can also input their own data on the web page.
Following is an example of an HTML page with textboxes that can be used to enter data in a form:
Alternatively, you can use variables to input information into the database. Example:
$first=$_POST[‘first’]; $last=$_POST[‘last’]; $phone=$_POST[‘phone’]; $mobile=$_POST[‘mobile’]; $fax=$_POST[‘fax’]; $email=$_POST[’email’]; $web=$_POST[‘web’]; … $query = “INSERT INTO contacts VALUES (”,’$first’,’$last’,’$phone’,’$mobile’,’$fax’,’$email’,’$web’)”; mysql_query($query);
This script is saved in the insert.php file, which can be called from the HTML form. Using this method, data entered in the web page form is stored in the defined variables, which are then passed to the PHP.
To display (or output) the entered data using PHP, you can use the following MySQL command with the result assigned to the variable.
$query=”SELECT * FROM contacts”; $result=mysql_query($query);
PHP provides 2 submission methods, GET and POST to get the data submitted by the form into your PHP script. GET method displays the variables and the data in the page address, while they are invisible in the POST method. For example, a script can be created that will display different web pages depending on the clicked link.
yourpage.php?user=david (to show David’s page) yourpage.php?user=tom (to show Tom’s page)
Name | Date | Fee | Know more |
---|