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
    
  
  
    
  | 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
    
  
  
    
  | 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
    
  
  
    
  | //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
    
  
  
    
  | <?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
    
  
  
    
  | <?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 | |
| $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 | |
| // 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 | |
| //insert new data to the table myGuests : | |
| $sql = "INSERT INTO MyGuests (firstname, lastname, email) | |
| VALUES ('John', 'Doe', '[email protected]')"; | |
| //check if the statement successfully applicated : | |
| if ($conn->query($sql) === TRUE) { | |
| $last_id = $conn->insert_id; | |
| echo "New record created successfully. Last inserted ID is: " . $last_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
    
  
  
    
  | <?php | |
| $servername = "localhost"; | |
| $username = "username"; | |
| $password = "password"; | |
| $dbname = "myDB"; | |
| // Create connection | |
| $conn = new mysqli($servername, $username, $password, $dbname); | |
| // Check connection | |
| if ($conn->connect_error) { |