0% found this document useful (0 votes)
19 views9 pages

Ost 5marks Ocr

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views9 pages

Ost 5marks Ocr

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

PHP Arrays

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.

$fruits = array("Apple", "Banana", "Cherry");


// or using short array syntax
$fruits = ["Apple", "Banana", "Cherry"];

o Associative Arrays: Arrays with namedkeys (strings).

Sages= array("John" => 25, "Jane" => 30);


// or using short array syntax
Sages= ["John" => 25, "Jane" => 30];

o Multidimensional Arrays: Arrays containing other arrays.

$students = array(
"John"=>array("age"=>25."grade"=> TA"),
"Jane"
=>array("age"
=>30,"grade"
=>"B")
);

Common PHP Array Functions

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.

$length= count($fruits); // Returns3

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.

$lastFruit = array_pop($fruits);// Removes"Orange"

0 unset(): Removesa specific element.

unset($fruits[ 1]); // Removes "Banana"

5. Searching for Elements:


0 in_array():
Checks
ifa valueexistsin anarray.

$exists = in_array("Apple", $fruits); // Returnstrue if "Apple" exists

6. Sorting Arrays:
0 sort(): Sorts an indexed array in ascendingorder.

sort($fruits); // Sorts the $fruits array

o asort(): Sorts an associative array in ascending order, maintaining key-value


associations.

asort($ages);// Sortsby valueswhile maintaining keys

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.

$slice = array_slice($fruits,1, 2); // Gets 2 elementsstarting from index |

9. Iterating Over Arrays:


0 foreach: A loop to iterate over elementsin an array.

foreach ($fruits as $fruit) {


echo $fruit;

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.

Stored procedures advantages

. 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.

The syntax for creating a basic stored procedure is as follows:

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.

This stored procedure example uses the following table:

CREATETABLEtestSP (
id int not null primary key auto_increment,
field_name varchar(25),
date_added datetime
) ENGINE=InnoDB;

The values of this table for testing purposes are as follows:

| id| field_name | date_added


PaeecceePeeeeeseeeeee Pewee eereeeree eect eee eee >

| 14] Value 1 | 2012-01-23 09:40:24


| 2| Value 2 | 2012-01-24 09:40:24
| 3 | Value 3 | 2012-01-25 09:40:24
| 41! Value 4 | 2012-01-26 09:40:24
| 5S | Value 5 | 2012-01-27 00:40:24
| 6 | Value 6 | 2012-01-30 00:40:24
| 7| Value 7 | 2012-01-31 00:40:24
| 8| Value 8 | 2012-02-81 00:40:24
| 9 | Value 9 | 2012-02-82 09:40:24
| 10 | Value 1@ | 2012-02-14 09:40:24
Pee ee Pees eeeneeeevee Poeoseeceeseseeeseeesesesee >

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:

CREATEPROCEDUREsp1 () SELECT* FROM testSP WHEREdate_added BETWEENDATE_SUB(NOW(),


INTERVAL7 DAY) AND NOW() //

2
Apache Authentication Module Functionality

Apache's authentication modules provide


a robust security framework for controlling
access to web resources. These modules
enable administrators to manage user
authentication, authorization, and access
control.

Key Components:

1. Authentication Modules: These modules


verify user identities using various
methods (e.g., username/password,
certificates, LDAP).

2. Authorization Modules: These modules


determine access levels based on user
identities, groups, and permissions.

3. Providers: These providers store and


manage user credentials and group
information.

Apache Authentication Modules:

1. mod_auth_basic: Basic HTTP


authentication using username/
password.

2. mod_auth_digest: Digest authentication


using MD5 hashing.
3
Functionality:

1. User Authentication: Verification of user


identities.

2. Authorization: Access control based on


user permissions.

3. Group Management: Management of


user groups.

4. Password Encryption: Secure storage of


passwords.

5. Session Management: Management of


user sessions.

Configuration:

1. .htaccess files: Configuration files for


2. ii
directory-level
httpd.conf:
{oy Mainsettings.
Apache configuration

3. LDAP configuration: Configuration for


LDAP-based authentication.

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?

- Benchmarking is a processof testing how fast and efficient a databaseserver is by


simulating different workloads.

- It helps identify the server’s performancelimits and find bottlenecks(things slowing it


down).

2. Why Benchmark Your Database?

- Tounderstand
howwellthedatabase
handles
a specificnumber
of usersandqueries.
- To test how the server performs under heavy load (lots of data or users).

- To compareperformancebefore and after changes(like tuning or hardwareupgrades).

3. Key QuestionsAnswered by Benchmarking

- How many queriesper secondcan the server process?


- How does the server behave when there are many users at the same time?

- How fast can it handle large data operations(reading, writing, and updating)?

4. Benchmarking Tools for MySQL

- mysqlslap: A built-in MySQL tool that simulatesuser load and measuresquery


performance.
- sysbench:An external tool that tests MySQL along with the CPU, memory, and I/O
(input/output) performance.

5. Example Benchmarking with ‘mysqlslap°

You can use the following command to test your MySQL databaseserver:

mysqlslap --concurrency=50--iterations=10 --query="SELECT * FROM your_table"


--create-schema=your_database --user=root --password

- --concurrency=50:Simulates50 usersrunning queries at the sametime.


- --iterations=10: Runs the test 10 times to get a reliable result.

- --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.

- --user and --password:Your MySQL login details.

6. Understanding Benchmark Results

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.

9. Common Benchmarking Scenarios


- Testing how many usersyour server can handle before it starts slowing down.

- Checking if the databaseperforms better after upgrading from HDD to SSD.

- Measuringperformanceimprovementsafter increasingservermemory or tuning MySQL


settings.

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.

Common Uses of "FLUSH:

- FLUSH PRIVILEGES**: Reloadsthe user privileges (permissions) without restarting the


server.This is useful when you add or change user accounts.

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;

Why Use FLUSH"?

- To apply changes(like new privileges) without restarting the server.


- To clean up or reset caches and internal resources.

2. The SHOW’ Command

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.

Common Uses of SHOW

- SHOWDATABASES:
Displays
a listofall databases
ontheMySQLserver.
SHOW DATABASES;

- SHOW TABLES: Shows all the tables in the current database.

USE your_database; -- Select a databasefirst


SHOW TABLES;

- 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;

Why Use ‘SHOW*?


- To monitor the database server's current state.

- To see details about databases, tables, and users.

- To check server configuration and performance.

You might also like