Professional Documents
Culture Documents
7.Slim: It's ideal for developing small RESTful APIs and web services. Slim
is lightweight and provides features like routing, middleware, and
dependency injection.
2. What is the use of session and cookies in PHP?
Sessions:
The server uses this session ID to associate data with the specific
client. Session data is typically stored on the server, either in memory,
on disk, or in a database.
Cookies:
Cookies are small pieces of data sent by the server and stored on the
client's browser. Unlike sessions, cookies can be both server-side and
client-side.
Cookies can have expiration dates, which determine how long they
remain valid on the client's browser.
In PHP, cookies can be set using the setcookie() function and accessed
via the $_COOKIE superglobal array.
3. What are the uses of PHP?
Web Development: PHP is most commonly used for creating dynamic and
interactive web pages. PHP is used in conjunction with HTML, CSS, and
JavaScript to build full-fledged web applications.
Command Line Scripting: PHP can also be used for writing command-line
scripts to perform various tasks on a server or a local machine.
Static Websites:
Static websites consist of web pages with fixed content that does not
change unless manually updated by a developer.
Static websites are suitable for simple sites with content that rarely
changes, such as informational websites, portfolios, or small business
websites.
Dynamic Websites:
Joomla: Joomla is another popular PHP-based CMS that is known for its
flexibility and extensibility.
Drupal: Drupal is a powerful CMS that is often used for building complex
and highly customized websites and web applications.
<?php
$servername = "localhost";
$username = "username";
$password = "password";
// Create connection
$conn = mysqli_connect($servername, $username, $password);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
?>
<?php
$sql = "CREATE DATABASE mydatabase";
if (mysqli_query($conn, $sql)) {
echo "Database created successfully";
} else {
echo "Error creating database: " . mysqli_error($conn);
}
?>
Close the Connection: After creating the database, it's good practice to close
the connection to the MySQL server using the mysqli_close() function.
Ex:-
<?php
// Close connection
mysqli_close($conn);
?>
7. How to encrypt password in PHP?
<?php
$plaintext_password = "user_password";
$hashed_password_from_database = "hashed_password_from_database";