Php
Php
Display Text
The following example shows how to output text with the echo command (notice that the text can contain HTML markup):
echo "<h2>PHP is Fun!</h2>";
echo "Hello world!<br>";
Display Variables
The following example shows how to output text and variables with the echo statement:
$txt1 = "Learn PHP";
$txt2 = "W3Schools.com";
echo "<h2>$txt1</h2>";
echo "<p>Study PHP at $txt2</p>";
What is MySQL?
• MySQL is a database system used on the web
• MySQL is a database system that runs on a server
• MySQL is ideal for both small and large applications
• MySQL is very fast, reliable, and easy to use
• MySQL uses standard SQL
• MySQL compiles on a number of platforms
• MySQL is free to download and use
• MySQL is developed, distributed, and supported by Oracle Corporation
• With PHP, you can connect to and manipulate databases.
• MySQL is the most popular database system used with PHP.
PHP 5 and later can work with a MySQL database using:
MySQLi extension (the "i" stands for improved)
PDO (PHP Data Objects)
For Linux and Windows: The MySQLi extension is automatically installed in most cases, when php5 mysql package is installed.
Connection to Server Close the Connection
Before we can access data in the MySQL database, we need to be The connection will be closed automatically when the script ends. To close the
able to connect to the server: connection before, use the following:
MySQLi Procedural:
Example (MySQLi Procedural)
mysqli_close($conn);
Creating a Database
The CREATE DATABASE statement is used to create a database in
MySQL.
Select a Database Listing Database
Listing Table Names
Creating a table
The CREATE TABLE statement is used to create a table in MySQL.
We will create a table named "MyGuests", with five columns: "id",
"firstname", "lastname", "email" and "reg_date":
The data type specifies what type of data the column can hold.
After the data type, you can specify other optional attributes for each
column:
• NOT NULL - Each row must contain a value for that column, null
values are not allowed
• DEFAULT value - Set a default value that is added when no other
value is passed
• UNSIGNED - Used for number types, limits the stored data to
positive numbers and zero
• AUTO INCREMENT - MySQL automatically increases the value of the
field by 1 each time a new record is added
• PRIMARY KEY - Used to uniquely identify the rows in a table. The
column with PRIMARY KEY setting is often an ID number, and is often
used with AUTO_INCREMENT
• Each table should have a primary key column (in this case: the "id"
column). Its value must be unique for each record in the table.
Inserting Data in the table
some syntax rules to follow:
The SQL query must be quoted in PHP
String values inside the SQL query must be quoted
Numeric values must not be quoted
The word NULL must not be quoted
The INSERT INTO statement is used to add new records to a MySQL
table:
• JavaScript:
Adds interactivity and dynamic features to websites (e.g., image sliders, form validation, and animations).
In CMS platforms, JavaScript is often used in plugins and extensions to enhance functionality.
• How CMS Integrates These Technologies:
A CMS abstracts the complexity of these technologies by providing a user-friendly interface for tasks like:
Adding and formatting content (relying on HTML).
Choosing or customizing design themes (using CSS).
Adding dynamic features like interactive menus or forms (powered by JavaScript).
Benefits of CMS
• Ease of Use: A CMS provides a graphical user interface (GUI) for content management, eliminating the need to write or edit code
manually. Users can easily create, edit, and publish content through drag-and-drop tools and pre-defined templates.
• Time Efficiency: With a CMS, users can quickly set up websites or update content without waiting for developers, significantly reducing
time-to-market.
• Cost-Effective: Open-source CMS platforms like WordPress are free to use, reducing the cost of building a website.
• Customizability: CMS platforms offer a wide range of themes and plugins/extensions, allowing users to add functionalities like contact
forms, SEO optimization, and e-commerce integration.
• Security: CMS platforms provide regular updates to address security vulnerabilities. Plugins and extensions for firewalls, SSL certificates,
and anti-spam tools help protect websites from cyberattacks.
• SEO Features: Many CMS platforms come with built-in SEO tools and these tools help optimize content for search engines by managing
metadata, keywords, and URL structures.
• Scalability: A CMS grows with your needs, making it suitable for both small businesses and large enterprises.
Types of CMS
Traditional CMS (or Coupled CMS)
• A traditional CMS integrates both the backend (content storage and management) and frontend (website display) in a single system.
Examples include WordPress, Joomla, and Drupal.
• These platforms are ideal for standard websites, blogs, or small businesses, offering ease of use and a rich ecosystem of plugins and
themes and Suitable for websites where content is primarily delivered through a single channel (e.g., desktop and mobile browsers).
• However, their tightly integrated structure may limit flexibility for advanced multi-channel content delivery.
Headless CMS
• A headless CMS separates the content management (backend) from content delivery (frontend).
• Content is delivered through APIs, allowing developers to create custom frontends for any platform.
• This approach is perfect for delivering content to multiple platforms, such as websites, mobile apps, and IoT devices.
• Highly flexible and future-proof for multi-channel content delivery and Developers have complete control over the frontend experience.
• However, it requires development expertise to build custom frontends.
Decoupled CMS
• A decoupled CMS is similar to a headless CMS but retains some built-in frontend capabilities for previewing content.
• Ideal for teams that want the flexibility of headless CMS with the added ability to preview content before publishing.
• Benefits are that it combines flexibility with usability and Supports multi-channel delivery while retaining some frontend features.
• Drawback is it is Slightly more complex than a traditional CMS.
SaaS CMS (Software-as-a-Service CMS)
• A SaaS CMS is a cloud-based content management system that operates on a subscription model, where the CMS provider hosts
the platform, manages its infrastructure, and takes care of updates, maintenance, and security
• The CMS is hosted on the cloud by the provider, eliminating the need for users to manage servers or hosting setups.Users can
access their CMS from anywhere with an internet connection.
• Cost-Effective as users pay a fixed subscription fee, which often includes hosting, security, and updates.
• No technical expertise required as SaaS CMS platforms are designed for simplicity, allowing users to manage their websites
without coding or technical know-how. Pre-built templates and intuitive interfaces make website creation straightforward.
• While SaaS CMS platforms offer a wide range of templates and features, they often have restrictions on advanced customization
compared to open-source CMS platforms like WordPress.
• Users are dependent on the SaaS provider for hosting and features, making migration to another platform more complex.
WordPress Development
WordPress is one of the most popular and free open-source content management systems (CMS) that allows users to create and manage
websites with ease.WordPress is known for its user-friendly interface, flexibility, and extensive customization options, built on PHP and
MySQL. It's widely used for blogging and enables users to update, customize, and manage their websites effortlessly through its intuitive
back-end CMS.
Theme Customization
A WordPress theme defines the design and layout of a website, controlling elements like fonts, colors, headers, footers, and page
structure. Customizing themes allows developers and users to create unique, visually appealing, and functional websites. While many
themes come with built-in options, more advanced customization can be achieved by editing code, using child themes, or employing
third-party tools like page builders.
It includes:
Appearance (Visual Design):
• Colors and Fonts: Modify primary and secondary color schemes and typography to align with branding.
• Header and Footer: Customize the menu layout, logo placement, and footer widgets or text.
• Backgrounds: Set custom images, videos, or solid colors for page backgrounds.
Custom CSS/JavaScript:
WordPress Customizer
The WordPress Customizer is an intuitive, built-in tool that allows users to modify their website’s design and settings without
needing to edit code.
• Customization:
Plugins enable site-specific customizations without altering the core files or themes.
Keeps custom features modular and independent.
• Monetization:
Developers can sell plugins as premium solutions to a wide audience.
Marketplaces like CodeCanyon or freemium models on the WordPress Plugin Repository make this viable.
• Integration:
Plugins act as bridges for integrating WordPress with third-party tools and services like payment gateways, CRMs, or marketing platforms.
Steps to Develop a WordPress Plugin • Write the Plugin Code:
• Plan the Plugin’s Functionality: Use hooks (actions and filters) to inject functionality into
WordPress.
Define the specific problem or functionality the plugin will
address. Test the Plugin:
Draft features and outline the user flow. Test on a local or staging environment before deploying to
live sites.
Types of Modules
• Core Modules: Built into Drupal (e.g., Node, Block, Views).
• Contributed Modules: Developed by the Drupal community and shared on Drupal.org (e.g., Webform, Pathauto).
• Custom Modules: Tailored specifically for a project or site.
Site Building in Drupal
Site building involves creating and structuring the website without heavy coding, using Drupal's interface and built-in tools.
Site-Building Techniques
Blocks
• Blocks are reusable pieces of content displayed in specific regions of the theme.
• Manage blocks via Structure > Block layout.
• Create custom blocks with specific content or functionality.
Views
• Views are used to create dynamic pages, blocks, and lists based on content or data.
• Provides filtering, sorting, and formatting options.
• Example: Create a list of blog posts with filters for categories
Content Types and Fields Menus
Content Types define the structure of the content you Menus in Drupal provide navigational structures for a
create. website, allowing users to access pages and other
resources. Drupal includes a built-in menu system that
supports creating, managing, and displaying menus on
Default Content Types your site.
• Article: Ideal for blogs or news.
• Basic Page: Used for static pages like "About Us.“ Types of Menus
• Main Navigation: The primary menu for the site.
Custom Content Types • Footer Menu: Links displayed in the footer.
• Create custom content types via Structure > Content • Custom Menus: User-defined menus for specific
types. purposes.
• Add specific fields like text, image, or file upload.
Menu Management
Fields • Manage menus via Structure > Menus.
• Fields are building blocks for content. • Add links to menus, configure their order, and assign
them to regions.
• Examples: Title, Body, Image, Date, Tags.
• Reusable fields can be shared across multiple content
types