Basic CRUD Operations for Demanding Programs
$ sudo update-alternatives --list php
$ sudo update-alternatives --config php
Apache:
$ sudo a2dismod php7.4
$ sudo a2enmod php8.3
$ sudo service apache2 restart
Command Line:
$ sudo update-alternatives --set php /usr/bin/php5.6
$ sudo a2enmod rewrite
$ sudo systemctl restart apache2
-> Then open: sudo nano /etc/apache2/sites-available/000-default.conf
-> Change:
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
$ composer create-project --prefer-dist laravel/laravel crudapplication "6.*"
$ composer create-project laravel/laravel crudapplication
$ composer require laravel/ui
$ php artisan ui bootstrap --auth
$ npm install
$ npm run dev
$ php artisan migrate
$ npm run build
$ php artisan make:migration create_contacts_table --create=Table_NAME
$ php artisan migrate
$ php artisan make:model Contact
$ php artisan make:controller ContactController --resource--model=Contact
$ Route::resource(‘/contact’,'App\Http\Controllers\ContactController');
$ php artisan serve
$ php artisan serve --host 192.168.89.83 --port 8080
$ composer install
$ composer update --ignore-platform-reqs
$ composer dump-autoload
$ composer update --no-scripts
$ composer dump-autoload -o
$ php artisan optimize:clear
$ php artisan cache:clear
$ php artisan config:clear
$ php artisan migrate
$ php artisan migrate --path=/database/migrations/2014_users_table.php #new created single file
$ php artisan migrate:refresh --path=/database/migrations/subcategory_description.php #update single file
# $table->unsignedBigInteger('user_id');
# $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
# Post Model Relationship Code
class Post extends Model
{
public function comments()
{
return $this->hasMany(Comment::class);
}
}
# Comment Model Relationship Code
class Comment extends Model
{
public function post()
{
return $this->belongsTo(Post::class);
}
}
# Display All Comments
public function show($postId)
{
$post = Post::with('comments')->find($postId);
return view('posts.show', compact('post'));
}
# Database Table Code
public function up()
{
Schema::table('your_table_name', function (Blueprint $table) {
$table->string('new_column1');
$table->integer('new_column2');
});
}
public function down()
{
Schema::table('your_table_name', function (Blueprint $table) {
$table->dropColumn('new_column1');
$table->dropColumn('new_column2');
});
}
$ php artisan optimize:clear
$ php artisan cache:clear
$ php artisan config:clear
## Department image 1
$image1 = $request->file('profile_pic');
if ($request->hasfile('profile_pic')) {
$extension = $image1->getClientOriginalExtension();
$department_image_name = $user->name . '-photo-.' . $extension;
$image1->move('assets/users/', $department_image_name);
$user->profile_pic = $department_image_name;
}
## Image Delete Code
public function destroy($id){
$item = reg_user::find($id);
if (!$item) {
return redirect()->route('users_home')->with('error', 'Item not found!');
}
$destination = public_path('/assets/users/') . $item->profile_pic;
if (File::exists($destination)) {
File::delete($destination);
}
$item->delete();
return redirect()->route('users_home')->with('success', 'Item deleted successfully!');
}
$ composer create-project --prefer-dist laravel/laravel crudapplication
$ npm install vue@latest
$ npm install @vitejs/plugin-vue
## if Error ##
npm i @vitejs/plugin-vue@4.0.0
## vite.config.js ##
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import vue from '@vitejs/plugin-vue';
export default defineConfig({
plugins: [
laravel({
input: [
'resources/sass/app.scss',
'resources/js/app.js',
'resources/css/app.css',
],
refresh: true,
}),
vue({
template: {
transformAssetUrls: {
base: null,
includeAbsolute: false,
},
},
}),
],
resolve: {
alias: {
vue: 'vue/dist/vue.esm-bundler.js',
},
},
});
## index.blade.php ##
head>
Document
/head>
@vite('resources/css/app.css')
@vite('resources/js/app.js')
## app.js ##
import { createApp } from 'vue';
import App from './App.vue'
import router from'./routes.js'
const app = createApp({});
createApp(App).use(router).mount("#app")
## App.vue ##
$ npm i vue-router@next
or
$ npm install vue-router@4
## routes.js ##
import { createWebHistory, createRouter } from 'vue-router'
import test from './test.vue'
const routes = [
{
name: 'test',
path: '/',
component: test,
},
];
const router = createRouter({
history: createWebHistory(),
routes,
});
export default router;
$ DEBUGBAR_ENABLED = FALSE
$ DEBUGBAR_ENABLED = TRUE
$ php artisan cache:clear
$ php artisan config:cache
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
\Debugbar::disable();
}
}
# I want to remove data-reactid="anythingcanbe" from while document is VSCode
$ \sdata-reactid="[^"]*"
$ sudo nano ~/.bashrc
$ alias python=var/location/python3.exe
$ source ~/.bashrc
$ mkdir foldername
$ rmdir foldername
$ touch filename.extension
$ rm filename.extension
$ cat filename
$ nano filename
root@linux:~/target_folder_in$ sudo ln -s /home/target_folder_out/Filename_YAMiN.yml
$ Go folder -> /etc/ and open hosts file and add 127.0.0.1 needyamin.com
$ sudo ln -s /etc/apache2/sites-available/needyamin.com.conf /etc/apache2/sites-enabled/
$ sudo systemctl restart apache2
$ git clone http://github.com/needyamin/target-repository.git
$ git init
$ git add .
$ git status
$ git commit -m "First commit"
$ git push origin main
$ git checkout -b yourbranchname
# Check Container Information
$ docker ps
# Access This container
$ docker exec -it php-container bash
# IF exec not working
$ docker exec -it f479be191869 sh
# Direct Exec CLI command inside Container
$ docker exec -it eb0b4128cd88 php artisan migrate
# Direct Run PHP Command Inside Docker
$ docker compose run --rm artisan migrate:fresh
$ docker compose down
$ docker compose build
$ docker compose up
# Rebuild the Dockerfile single image:
$ docker compose build php
$ sudo docker builder prune
$ sudo docker system prune -a --volumes
$ sudo docker system prune -a
# Stop All Running Containers
$ docker stop $(docker ps -q)
# Remove All Containers
$ docker rm $(docker ps -a -q)
# Combined Command to Stop and Remove All Containers
$ docker stop $(docker ps -q) AND docker rm $(docker ps -a -q)
$ sudo usermod -aG docker $USER
$ newgrp docker
# Check Docker Status
sudo systemctl status docker
# Test Docker Installation
$ docker run hello-world
$ docker compose build
# The following builds the images if the images do not exist and starts the containers:
$ docker compose up
# If you add the --build option, it is forced to build the images even when not needed:
$ docker compose up --build
# The following skips the image build process:
$ docker compose up --no-build
$ docker build . -t webapp
# Run a container with
$ docker run --rm -it -p 8080:80 webapp
$servername = "localhost";
$username = "username";
$password = "password";
// Connection Name
$conn = new mysqli($servername, $username, $password);
// Check Connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
$servername = "localhost";
$username = "username";
$password = "password";
try {
$conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
}
catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO MyGuests (firstname, lastname, email) VALUES ('John', 'Doe', 'john@example.com')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "
" . $conn->error;
}
$conn->close();
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDBPDO";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO MyGuests (firstname, lastname, email) VALUES ('John', 'Doe', 'john@example.com')";
// use exec() because no results are returned
$conn->exec($sql);
echo "New record created successfully";
}
catch(PDOException $e) {
echo $sql . "" . $e->getMessage();
}
$conn = null;
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// sql to delete a record
$sql = "DELETE FROM MyGuests WHERE id=3";
if ($conn->query($sql) === TRUE) {
echo "Record deleted successfully";
} else {
echo "Error deleting record: " . $conn->error;
}
$conn->close();
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDBPDO";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// sql to delete a record
$sql = "DELETE FROM MyGuests WHERE id=3";
// use exec() because no results are returned
$conn->exec($sql);
echo "Record deleted successfully";
}
catch(PDOException $e) {
echo $sql . "" . $e->getMessage();
}
$conn = null;
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id, firstname, lastname FROM MyGuests";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "
";
}
} else {
echo "0 results";
}
$conn->close();
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT id, firstname, lastname FROM MyGuests";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "";
}
}
else {
echo "0 results";
}
mysqli_close($conn);
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "UPDATE MyGuests SET lastname='Doe' WHERE id=2";
if ($conn->query($sql) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}
$conn->close();
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDBPDO";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "UPDATE MyGuests SET lastname='Doe' WHERE id=2";
// Prepare statement
$stmt = $conn->prepare($sql);
// execute the query
$stmt->execute();
// echo a message to say the UPDATE succeeded
echo $stmt->rowCount() . " records UPDATED successfully";
}
catch(PDOException $e) {
echo $sql . "
" . $e->getMessage();
}
$conn = null;
# Connect to mysql server
$connection = new mysqli ('localhost','username','password','database_name');
# If Condition Check Error
if ($connection->connect_error) {
die("database not found"); #data stop;
}
# If Condition Check True
else {
#print"success";
}
############ When Clicked Action POST Start ############
if(isset($_POST['submit_hit'])) {
# Store post value data in Variables
$f = $_POST['fname'];
$l = $_POST['lname'];
$e = $_POST['email'];
$p = $_POST['password'];
$p = md5($p);
# Fire SQL Query
$sql = "INSERT INTO `sign_up` (`id`, `fname`, `lname`, `email`, `password`) VALUES (NULL, '$f', '$l', '$e', '$p')";
$connection->query($sql);
echo "your sign up process is successfully done";
}
############ When Clicked Action POST End ############
# Connect To The Database Server
$connection = new mysqli ('localhost','needyamin','Yamin143','project2');
# SELECT ALL FROM Database Table
$f = "SELECT * FROM `sign_up`";
$result = $connection->query($f);
# While Loop Fetch All Table Rows
while ($row = $result->fetch_assoc()){
# Echo your Rows
echo $row['id'];
echo $row['fname'];
echo $row['lname'];
echo $row['email'];
echo $row['password'];
};
CREATE TABLE MyGuests (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)
INSERT INTO MyGuests (firstname, lastname, email) VALUES ('John', 'Doe', 'john@example.com')
SELECT * FROM MyGuests
or
SELECT id, firstname, lastname FROM MyGuests
UPDATE MyGuests SET lastname='Doe' WHERE id=1
DELETE FROM MyGuests WHERE id=3
Inner Join
SELECT column_name(s) FROM table1 INNER JOIN table2 ON table1.column_name = table2.column_name;
LEFT JOIN
SELECT column_name(s) FROM table1 LEFT JOIN table2 ON table1.column_name = table2.column_name;
RIGHT JOIN
SELECT column_name(s) FROM table1 RIGHT JOIN table2 ON table1.column_name = table2.column_name;
Full JOIN
SELECT column_name(s) FROM table1 FULL OUTER JOIN table2 ON table1.column_name = table2.column_name WHERE condition;
AND
SELECT column1, column2, FROM table_name WHERE condition1 AND condition2 AND condition3;
OR
SELECT column1, column2, FROM table_name WHERE condition1 OR condition2 OR condition3;
NOT
SELECT column1, column2, FROM table_name WHERE NOT condition;
SELECT column1, column2, FROM table_name WHERE columnN LIKE % pattern values %;
DESC
SELECT column1, column2, FROM table_name ORDER BY column1, column2, DESC;
ASC
SELECT column1, column2, FROM table_name ORDER BY column1, column2, ASC;
SQL BACKUP DATABASE
BACKUP DATABASE testDB TO DISK = 'D:\backups\testDB.bak';
SQL DROP DATABASE
DROP DATABASE databasename;
$ pip3 install django
$ django-admin startproject name
$ python manage.py runserver
$ python manage.py startapp name
$ pip3 install django
update
$ sudo apt-get install python3-pip
$ sudo pip3 install virtualenv
$ virtualenv venv
you can use any name insted of venv
$ virtualenv -p /usr/bin/python2.7 venv
$ source venv/bin/activate
(Windows) $ venv\Scripts\activate
$ source venv/bin/activate.fish
$ deactivate
$ virtualenv -p python3 myenv
$ python3 -m venv myenv
$ pip install -r requirments.txt