Exercise Questions
Question 1:
$locations = array('Selangor' => array('PJ', 'Puchong', 'Ampang'), 'Penang' => array('George Town', 'Seberang Jaya'), 'Sarawak' => array('Kuching', 'Miri', 'Bintulu'));
1. Write a single line code to output Seberang Jaya
2. Write a single line code to find the total number of towns in Penang
3. Using loop statements, create and HTML output in the following format:
Locations in Selangor: PJ, Puchong, Ampang
Locations in Penang: George Town, Seberang Jaya
Locations in Sarawak: Kuching, Miri, Bintulu
4. Write a single line code to insert the location \"Prai\" to the end of the array \"Penang\".
Overwrite \"Puchong\" with \"Damansara\" in the array \"Selangor\"
Question 2: Loop
Using a loop statement, produce the following output:
3, 6, 9, 12, 15, 18, 21
Question 3: Arrays
Output the values in the following array in ascending order using your preferred sort algorithm (do not use the asort() PHP function):
array(10, 38, 3, 58, 1, 4, 0, 29, 48, 29, 22, 66, 23, 76);
Question 4: PHP Date/Time
Using mktime() in PHP, find out what day of the week is it on your 30th birthday
Question 5: Database
Using SQL, find out the date 60 days ago.
Question 6: Database
Study and analyse the following table structure:
employees(employee_id, full_name, dept_id, position, phone, fax)
departments(dept_id, dept_name, hod_manager)
attendance(attendance_id, employee_id, clock_in, clock_out)
payroll(payroll_id, employee_id, payroll_date, gross_salary, total_claims,
total_deductions, net_salary)
1. Create a database and its tables based on the above definition
2. Produce the SQL statement to retrieve all employees arriving to work after 9:00am in the last 25 days
3. Produce the SQL statement to retrieve all employees in descending order with gross salary below 5,000.00 and total claims above 1500.00 in the last 25 days
4. Produce the SQL statement to retrieve all employees' full name, position, and phone from IT department (dept_id as '1000') who leaves work after 9:00pm in the last 25 day
5. Produce the SQL statement to retrieve only 100 employees\nProduce the SQL statement to retrieve the top 10 highest earning employees
JAWAPAN ADA DI SINI.
Sunday, October 30, 2011
Install EasyPHP
- Layari http://www.easyphp.org/download.php
- Pilih version yang dikehendaki (EasyPHP 5.3.3.1) PHP 5.3.3 | Apache 2.2.17 | MySQL 5.1.52 | PhpMyAdmin 3.3.8
- Klik EasyPHP 5.3.3.1, save dan install
- Pastikan EasyPHP running. (Start - All Programs - EasyPHP 5.3.3.1 - kedua2 trafic light Apache & MySQL berwarna hijau)
- Buat Konfigurasi - (right click - configuration - Apache) - find AddType application/x-httpd-php .phtml .pwml .php5 .php4 .php3 .php2 .php .inc
- Right click - configuration - PHP (find error_reporting - error_reporting = E_ALL | E_STRICT tukar kepada error_reporting = E_ALL & ~E_NOTICE)
- Scroll down dan pastikan display_errors = On, log_errors = On, register_globals = Off, file_uploads = On, upload_max_filesize = 2M <== boleh tukar nilai lebih besar
- Buka EasyPHP folder C:\Program Files\EasyPHP-5.3.3.1\www (www utk save website) - setiap file buka guna crimson (JANGAN guna notepad).
Install Crimson Editor
- Layari http://www.crimsoneditor.com
- Klik Download
- Pilih Crimson Editor 3.70 Release
- Save dan Install
Saturday, October 29, 2011
MySQL
MySQL CLASS
----------------------------------------------------------------------------------------
Day 1 (17hb. 10 2011)
- Create database database_name;
- Create table tables_name( NAME DATA-TYPE( 00) NOT NULL;
- ALTER TABLES TABLESNAME ADD TABLESCONTENT DATATYPE(00) NOT NULL;
- ALTER TABLES TABLESNAME CHANGE SALAHTABLESNAME TABLESCONTENT DATATYPE(00) NOT NULL;
- publish ENUM('Y','N') not null default 'N' );
- SHOW DATABASES;
- USE DATABASENAME;
- SHOW TABLES;
- DESCRIBE TABLES;
- DROP DATABASE database_name;
----------------------------------------------------------------------------------------
Day 2 (18hb. 10 2011)
- Jawapan Untuk EIP case study
- INSERT INTO tables_name VALUES('value');
- INSERT INTO tables_name (field) VALUES('value');
- INSERT INTO tables_name SET field ='value';
- UPDATE students SET field ='value';
- UPDATE students SET field ='value' WHERE field='value'; with condition
- SELECT*FROM tables;
- SELECT*FROM tables WHERE YEAR(dcb)<'1995';
- SELECT*FROM field FROM tables WHERE YEAR(dcb)<'1995';
- SELECT user,password, host FROM user;
- DELETE FROM tables WHERE YEAR(field)<'CONDITION';
- TRUNCATE tables;
- START TRANSACTION ----> ROLLBACK OR COMMIT
- START TRANSACTION ----> SAVEPOINT NAME
...................................................................................
Day 3 (19hb. 10 2011)
- Stored Precedure;
- delimiter { (can be other symbols)CREATE PROCEDURE procedure_name(OUT table_field INT)BEGINtable_field FROM tables;SELECT COUNT(*) INTO
END{
delimiter ;
CALL procedure_name(@VALUE);
SELECT @VALUE;
delimiter { (example stored procedure without tables)
CREATE PROCEDURE gabung(IN data1 varchar(10), IN data2 varchar(10), OUT result varchar(30))
BEGIN
SELECT CONCAT_WS("-",data1,data2) into result;
END{
delimiter ;
CALL gabung("kenapa","lembab", @test);
SELECT @test;
CREATE FUNCTION hello(str char(20))
RETURNS char(50) DETERMINISTIC (if function return a same value(the process can be faster))
RETURN CONCAT('hello,',str);
SELECT hello('universe');
delimiter { (after)
CREATE TRIGGER name_trigger AFTER INSERT ON tables1 FOR EACH ROW
begin
INSERT INTO tables2 SET field(tables2)=new.field(
end{
delimiter ;
...................................................................................
Day 4 (20hb. 10 2011)
- SELECT user,password, host FROM user;
- CREATE USER 'azlirul'@'localhost' IDENTIFIED BY 'BC022001'; lLocalhost--> identify user from where(it can be [ip address,domain or machine name]
- DROP USER 'azlirul'@'google.com';
- RENAME USER 'azlirul'@'google.com' to 'azlirul'@'10.10.10.2';
- SET PASSWORD FOR 'azlirul'@'10.10.10.2' = password('azlirul');
- SHOW GRANTS FOR 'azlirul'@'10.10.10.2';
- GRANT SELECT,INSERT,DELETE ON eip.* TO 'azlirul'@'10.10.10.2';
- GRANT CREATE,SELECT,INSERT,DELETE,
UPDATE ON eip.* TO 'azlirul'@'10.10.10.2' WITH GRANT OPTION; - REVOKE ALL PRIVILEGES, GRANT OPTION ON mydb.* 'azlirul'@'10.10.10.2';
- revoke all privileges on *.* from 'account1'@'localhost';
...................................................................................
Day 5 (21hb. 10 2011)
- RUJUK BUKU NOTA ANDA (2 last topic)
RESET PASSWORD
- Start ---> control panel ---> Administrative Tools ---> service stopmysql
- create txt file
- type this text
UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
FLUSH PRIVILEGES;
FLUSH PRIVILEGES;
- save as mysql-init.txt on c:\
- type this on command prompt (windows+R --->cmd)
C:\> C:\mysql\bin\mysqld-nt --init-file=C:\\mysql-init.txt
" -nt " not for windows 7 , so just throw away -nt code
- log in mysql -u root -p[newpassword]
- PERHATIAN !!!!!: after that delete file mysql-init.txt on c:\
------------------------------------------------------------------------------------------------
LOG CODE (on my.ini)
[mysqld]
# The TCP/IP Port the MySQL Server will listen on
port=3306
# Update 18 OCT 2011
# Contains all SQL statements activities
# Useful to identify SQL statement errors
general_log=1
general_log_file="c:/mysql.log"
# The TCP/IP Port the MySQL Server will listen on
port=3306
# Update 18 OCT 2011
# Contains all SQL statements activities
# Useful to identify SQL statement errors
general_log=1
general_log_file="c:/mysql.
-------------------------------------------------------------------------------------------------------------------------
RUJUKAN WEB
-------------------------------------------------------------------------------------------------------------------------
- http://www.mysql.com/
- http://www.mysql.com/
downloads/mysql/ - http://dev.mysql.com/doc/
refman/4.1/en/resetting- permissions.html - http://search.oracle.com/
search/search?q=how+to+reset+ password&group=MySQL&x=0&y=0 - http://ss64.com/sql/grant_
user.html - http://msdn.microsoft.com/en-
us/library/ms178569.aspx - http://www.java2s.com/
Tutorial/MySQL/0540__ Privilege/0120__REVOKE.htm - http://en.wikipedia.org/wiki/
Kernel_(computing) <---- about kernel - http://sqlzoo.net/hack/
- http://www.windowsecurity.com/
articles/Hacking_an_SQL_ Server.html
--------------------------------------------------------------------------------------------------------------------------
- GeneticNEO rest Studio28Amirul Azlirul Azwan B. Abdul Aziz,SMK Raja Muda Musa,ICT selangor,Kementerian Pendidikan Selangor.
Subscribe to:
Posts (Atom)