Ost 5marks Ocr
Ost 5marks Ocr
1. Definition:
o An array in PHP is a data structure that can hold multiple values under a single
variable name. PHP supports both indexed and associative arrays.
2. Types of Arrays:
o Indexed Arrays: Arrays with numeric keys.
$students = array(
"John"=>array("age"=>25."grade"=> TA"),
"Jane"
=>array("age"
=>30,"grade"
=>"B")
);
1. Creating Arrays:
0 array(): Createsan array (can also use []).
o Example: $array = array(1, 2, 3); or $array = [1, 2, 3];
2. Array Length:
o count(): Returns the number of elements in an array.
3. Adding Elements:
0 array_push():Adds one or more elementsto the end of an array.
array_push(S$fruits,
"Orange");// Adds "Orange" to the end
4. Removing Elements:
0 array_pop(): Removes the last element from an array and returns it.
6. Sorting Arrays:
0 sort(): Sorts an indexed array in ascendingorder.
7. Combining Arrays:
oO array_merge(): Merges one or more arrays.
$merged= array_merge($fruits,$moreFruits);
8. Array Slicing:
0 array_slice():
Extracts
a portion
of an array.
1
WHAT ARE STORED PROCEDURES?
A stored procedure is a segment of declarative SQL statements stored inside the database catalog. A
stored procedure can be invoked by triggers, other stored procedures, and applications such
as Java, Python, PHP.
You might be thinking that you don’t store any procedures on the web server, but in fact you do.
. Better performance—Stored procedures exist as precompiled SQL in the database, so a typical two-
step process (compile and execute) becomes a single-step process (execute).
. Ease of maintenance—Maintaining one statement in one place (the database) is significantly less time-
consuming than maintaining one statement in numerous places, such as all through scripts on your web
server.
CREATEPROCEDURE
procedure_name () query //
An example of a useful stored procedure is the SQL query used to generate a report of some sort—be it
financial data, sales inventory, or otherwise; just imagine a complex query that involves a lot of
processing.
CREATETABLEtestSP (
id int not null primary key auto_increment,
field_name varchar(25),
date_added datetime
) ENGINE=InnoDB;
For this example, the stored procedure simply selects all data from the testSP table that has been added
in the past 7 days. The name of the stored procedure is sp1:
2
Apache Authentication Module Functionality
Key Components:
Configuration:
4
Example Configuration:
# Basic Authentication
AuthType Basic
AuthName ‘Restricted Area’
AuthUserFile /path/to/password/file
# LDAP Authentication
AuthType Basic
AuthLDAPUrl
AuthLDAPGroupAttribute
Ccn=admins,ou=groups,dc=example,dc=com
Require groupIdap://Idap. memberUid
5
Notes: Benchmarking Your DatabaseServer
1. What is Benchmarking?
- Tounderstand
howwellthedatabase
handles
a specificnumber
of usersandqueries.
- To test how the server performs under heavy load (lots of data or users).
- How fast can it handle large data operations(reading, writing, and updating)?
You can use the following command to test your MySQL databaseserver:
- --query: The SQL query you want to test (e.g., retrieving or inserting data).
- --create-schema:The name of the databasewhere you’re running the test.
Afterrunninga benchmark
test,you’
ll getresultslike:
- Average query time: How long each query took on average.
- Transactionsper second: How many queries the server can handle in one second.
- Concurrency: How well the server handles many usersat the sametime.
7. Types of Tests
- Read Performance: How quickly the server retrieves data from the database(e.g., using
SELECT queries).
- Write Performance: How fast data can be added, updated,or deleted (e.g., using INSERT,
UPDATE, DELETE queries).
6
8. What to Do with Benchmark Results
- Find Bottlenecks:Identify what is slowing down your database,whether it’s the CPU,
memory, or disk.
- Optimize: After finding the slow parts, you can adjust MySQL settings(like increasing
memory) or upgradehardwareto improve performance.
- TestChanges:Benchmarkagain after making changesto ensureperformancehas
improved.
7
1. The ‘FLUSH’ Command
The ‘FLUSH’ command ts used to refresh or reset various aspectsof MySQL’s internal
system, such as caches,logs, or privileges.
FLUSH PRIVILEGES;
- FLUSH TABLES: Closes all open tables and clears table cache. This is often used for
maintenance purposes.
FLUSH TABLES;
- FLUSH LOGS: Forces MySQL to close and reopen its log files (useful for rotating logs).
FLUSH LOGS;
- FLUSH HOSTS: Clears the cache of hostnamesthat have failed to connect to MySQL. This
is useful if MySQL temporarily blocks connectionsdue to too many failures.
FLUSH HOSTS;
The ‘SHOW’ command is used to display information about the MySQL server, such as
databases,tables, user privileges, or server status.
8
2. The SHOW’ Command
The ‘SHOW’ command is usedto display information about the MySQL server,such as
databases,tables, user privileges, or server status.
- SHOWDATABASES:
Displays
a listofall databases
ontheMySQLserver.
SHOW DATABASES;
- SHOW COLUMNS: Displays details about the columns (fields) in a table, including data
types and other properties.
SHOWCOLUMNSFROM
your_table;
- SHOW VARIABLES: Shows the current MySQL server configuration settings (like
memory limits, timeout settings, etc.).
SHOW VARIABLES;
- SHOW PROCESSLIST: Lists all active connections and queries currently running on the
MySQL server. This helps monitor performance.
SHOW PROCESSLIST;
- SHOW STATUS: Displays server status information such as uptime, query statistics, and
connection info.
“sal
SHOW STATUS;