This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// sql to create table | |
$sql = "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 | |
)"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$conn->close(); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Create database | |
$sql = "CREATE DATABASE myDB"; | |
if ($conn->query($sql) === TRUE) { | |
echo "Database created successfully"; | |
} else { | |
echo "Error creating database: " . $conn->error; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$servername = "HOSTNAME"; //Cpanel hostname to MySQL is: ****localhost**** . | |
$username = "USERNAME"; | |
$password = "PASSWORD"; | |
//Create connection | |
$conn = new mysqli($servername, $username, $password); | |
// Check connection | |
if ($conn->connect_error) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//create html element: | |
function eHtml(data) { | |
data.type ? e = $('<' + data.type + '>') : e = $('<div>'); | |
if (data.class) { | |
e.addClass(data.class); | |
} | |
if (data.id) { | |
e.attr('id', data.id); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
router.get('/getOne', async(req, res) =>{ | |
try { | |
if(!req.query.id){ | |
throw {message: 'add the post id in the request'} | |
} | |
const id = req.query.id; | |
//be carful to add the the tags field name in the model | |
//and not the Model Name or ref |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
router.get('/addPost', async(req, res) =>{ | |
try { | |
// add post: | |
const post = new Post({ | |
title: 'Post 3 title', | |
des: 'Post 3 Description', | |
body: 'Post 3 Body', | |
tags: ['5dba7d7ae842b83c84344755', '5dba7eab7fb2bf4fe0d1122d', 'another tag id and so on'] | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const postSchema = new mongosse.Schema({ | |
title: {type: String, required: true}, | |
des: {type: String, required: true}, | |
body: {type: String, required: true}, | |
tags: [{type: mongosse.Schema.Types.ObjectId, required: true, ref:'Tag'}] | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Ex: create category container | |
/// add the consts in data obj can be not definde just the type is requseted | |
const catContainer = htmlE({ | |
type: 'div', // type of the element | |
classes: 'first-class second-class', // css classes | |
id: elementId, // element id | |
container: container, // parent container to append to | |
onClick: catClick, // on element click function | |
params: [category] // on element click function params | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static function postRequest($url, $postData, $headers){ | |
//init curl: | |
$ch = curl_init($url); | |
// Configuring curl options | |
$options = array( | |
CURLOPT_CUSTOMREQUEST => 'POST', | |
CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_POSTFIELDS => $postData, | |
CURLOPT_HTTPHEADER => $headers | |
); |