filmov
tv
Connecting and executing SQL to Displaying records from MySQL database table by using PHP

Показать описание
Part 1 : Connecting to MySQL
Part 2 : Query and executing the query.
Part 3 : Displaying the records with links to all details of a single record.
You can download the SQL dump of student table , source code for all the scripts and supporting function details from this link.
for Part 1 : about connection
for Part 3 : About displaying single record
This connection string with connection object we will be using in different files. How to manage this connection object in a common place for easy maintenance and security? If the user wants to change the login password of MySQL then by keeping it at a common place this can be done easily. No need to update all the connected pages that are using this connection object. Keep this connection details inside a commonly used PHP file and never use any text or flat file which can be opened by using a browser and that will expose all the login credentials.
On Part II we will create the Query. This query we will use to collect four columns of data from our sample table. We will also use LIMIT command in our Query to restrict the number of records to 5 only starting from first record. On execution of the query we will get a set of 5 records from the table starting from 0 rows or fist row. We will loop through the record set to get each row of data as array by using WHILE loop in PHP. The elements of this row array is our data of each column of student table.
We can also use PDO ( Portable Data Object ) data connection to connect to MySQL database and manage the records.
Directly using the value from the address bar by using GET method can create problem as malicious code can be injected into our query. To overcome this issue, we have to use prepare statement by using parameters while executing the query. In such case the query and the parameters will travel separately to MySQL database. Full details of the record is displayed after successfully executing the query.
Download the source code of all the script s and SQL dump of student table from the URL given at top.
Part 2 : Query and executing the query.
Part 3 : Displaying the records with links to all details of a single record.
You can download the SQL dump of student table , source code for all the scripts and supporting function details from this link.
for Part 1 : about connection
for Part 3 : About displaying single record
This connection string with connection object we will be using in different files. How to manage this connection object in a common place for easy maintenance and security? If the user wants to change the login password of MySQL then by keeping it at a common place this can be done easily. No need to update all the connected pages that are using this connection object. Keep this connection details inside a commonly used PHP file and never use any text or flat file which can be opened by using a browser and that will expose all the login credentials.
On Part II we will create the Query. This query we will use to collect four columns of data from our sample table. We will also use LIMIT command in our Query to restrict the number of records to 5 only starting from first record. On execution of the query we will get a set of 5 records from the table starting from 0 rows or fist row. We will loop through the record set to get each row of data as array by using WHILE loop in PHP. The elements of this row array is our data of each column of student table.
We can also use PDO ( Portable Data Object ) data connection to connect to MySQL database and manage the records.
Directly using the value from the address bar by using GET method can create problem as malicious code can be injected into our query. To overcome this issue, we have to use prepare statement by using parameters while executing the query. In such case the query and the parameters will travel separately to MySQL database. Full details of the record is displayed after successfully executing the query.
Download the source code of all the script s and SQL dump of student table from the URL given at top.
Комментарии