Web Technology and DBMS
Web Technology and DBMS
print $_POST['username'];
print $_REQUEST['username'];
import_request_variables('p', 'p_');
print $p_username;
print $HTTP_POST_VARS['username'];
Connecting to MySQL
• Before accessing the DB, we have to open a connection to the DB
• Use this to open a connection
mysql_connect(host,username,password)
• Use this to close the connection (for security)
mysql_close(pengenal_hubungan);
Selecting DB
Accessing a table
• To use a query:
mysql_query(query,token)
• Count column:
mysql_num_fields
(queryresult_returns)
• Count records:
mysql_num_rows
(queryresult_returns)
19
Create (C in CRUD)
• SQL for inserting:
INSERT INTO `tablename`
(`column1’, `column2`,..)
VALUES (‘value1’, ‘value2‘,..)";
e.g.
INSERT INTO `table1` (`nama`,
`umur`) VALUES ('Andi', '15')";
22
Delete (D in CRUD)
DELETE FROM `tablename` WHERE
‘columname’=‘value‘
• E.g.
• DELETE FROM `tabel1` WHERE
`nama`=‘Andi’ menghapus
semua record jika nama=‘Andi’
Conclusion
• Using mysql_connect, PHP can communicate with database, in any
servers
• Hence, PHP can be used mostly to CRUD any data
• Using a simple combination of PHP, MySQL, HTML, and CSS, you can
build a powerful (and dynamic) web app
• Add some javascripts, and you can do Asynchronous processing