Skip to main content

Posts

Setup a Virtual Host on WAMP

Setup a Virtual Host on WAMP Running several name-based web sites on a single IP address. Step 1: Add Code in file C:\wamp\bin\apache\apache2.4.9\conf\httpd.conf uncomment the LoadModule vhost_alias_module modules/mod_vhost_alias.so uncomment the Include conf/extra/httpd-vhosts.conf Step 2: Add VirtualHost code in file C:\wamp\bin\apache\apache2.4.9\conf\extra\httpd-vhosts.conf # Ensure that Apache listens on port 80 Listen 80 <VirtualHost *:80>     ServerAdmin sudhir@techsudhir.com     DocumentRoot "C:/wamp/www/wordpress"     ServerName techsudhir.local ServerAlias www.techsudhir.local     ErrorLog "logs/techsudhir.local-error.log"     CustomLog "logs/techsudhir.local-access.log" common <Directory "/"> Deny from all Allow from 127.0.0.1 </Directory> </VirtualHost> Save All Step 3: Add Code in file C:\Windows\System32\drivers\etc\hosts 127.0.0.1  techsudhir.local...

Database manipulation in MongoDB

Database manipulation in MongoDB Basic database queries for MongoDB The remove() Method Syntax: >db.COLLECTION_NAME.remove(DELLETION_CRITTERIA) Example: >db.Employee.remove({'title':'MongoDB Overview'}); Remove Only One Syntax: >db.COLLECTION_NAME.remove(DELETION_CRITERIA,1) And/OR Condition >db.Employee.find({$and:[{"by":"Sudhir"},{"title": "Testing MongoDB Database"}]}) >db.Employee.find({$or:[{"by":"Sudhir"},{"title": "Testing MongoDB Database"}]}) Using AND and OR Together >db.mycol.find({"likes": {$gt:10}, $or: [{"by": "Sudhir"},{"title": "Testing MongoDB Database"}]}) The save() method replaces the existing document with the new document passed in the save() method. Syntax: >db.COLLECTION_NAME.save({_id:ObjectId(),NEW_DATA}) Example: >db.mycol.save( { "_id" : Objec...

JSON and JSONP in Javascripit

JSON and JSONP in Javascripit JSON is a subset of the object literal notation of JavaScript. JSON in JavaScript Example: var myJSONObject = {"Address": [ {"city": "Azamgarh", "state": "Uttar Pradesh", "country": "INDIA"}, {"city": "Lucknow", "state": "Delhi", "country": "USA"}, {"city": "Noida", "state": "Goa", "country": "UK"} ] }; Code Explaination: Here bindings is an object. It contains array of 3 object. Members can be retrieved using dot or subscript operators. Example : myJSONObject.bindings[0].method JSON Objects JSON objects are written inside curly braces Example : var name = {"firstName":"John", "lastName":"Doe"} JSON Arrays JSON arrays are written inside square brackets. Example : var employeeList = "emplo...

Beginner guide to Mongodb database

Beginner guide to Mongodb database MongoDB is an open-source document database that provides high performance, high availability, and automatic SCALING . MongoDB documents are similar to JSON objects. MongoDB stores data in the form of BSON -Binary encoded JSON documents which supports a rich collection of types. Fields in BSON documents may hold arrays of values or embedded document s. Structural aspects of MongoDB 1. Data Model A record in MongoDB is a document, which is a data structure composed of field and value pairs. MongoDB stores documents in collections.Collections are analogous to tables in relational databases.  Documents stored in a collection must have a unique _id field that acts as a primary key.  There are two ways to stores documents in a collection either in Normalized for or embedded into another document itself. a) Normalized Data Models The relationships between data is stored by links (references) from one document to another.   ...

Create PHP PDO wrapper class

Create PHP PDO wrapper class Step 1: Create Config file config.php <?php ini_set("display_errors", 1);   define('DB_HOST', "localhost"); define('DB_NAME', "pdoTest"); define('DB_USER', "root"); define('DB_PASS', "root"); ?> Step 2: Now create wrapper class Database.php <?php class Database {     private $conn; private $stmt;     function __construct (){  include_once 'config.php'; try{ $this->conn = new PDO("mysql:host=".DB_HOST.";dbname=".DB_NAME."", DB_USER, DB_PASS);  $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); return $this->conn; }catch(PDOException $e){             return $e->getMessage();         } } public function query ($query){ $query = trim($query); try { $this->stmt = $this->conn->prepare($query); return $this; }catch (PDO...

MySql Trigger

MySql Trigger A trigger is a stored program which executed automatically to respond to a specific event. such as insert, update or delete occurred in a table. Syntax : CREATE     TRIGGER `event_name` BEFORE/AFTER INSERT/UPDATE/DELETE     ON `database`.`table`     FOR EACH ROW BEGIN -- trigger body -- this code is applied to every  -- inserted/updated/deleted row     END; Notes: event_name :  All triggers must have unique names within a schema trigger_event : Indicates the kind of operation that activates the trigger. tbl_name : The trigger becomes associated with the table named tbl_name Example 1: Suppose you have user table and user_audit table and you want to track new users only. Then you have to create a trigger DELIMITER $$ CREATE TRIGGER `blog_after_insert` AFTER INSERT  ON `user`  FOR EACH ROW  BEGIN SET @changetype = 'NEW'; INSERT INTO user_audit (user_id, change...

CakePHP Interview Question and Answer

CakePHP Interview Question and Answer What is the first file that gets loaded when you run a application using cakephp? Answer: bootstrap.php     You can be changed it either through index.php , or through .htaccess     How to change via webroot > index.php         if (!defined('CAKE_CORE_INCLUDE_PATH')) {         if (function_exists('ini_set')) {             ini_set('include_path', ROOT . DS . 'lib' . PATH_SEPARATOR . ini_get('include_path'));         }         if (!include('Cake' . DS . 'bootstrap.php')) { // Change bootstrap.php file to any file name             $failed = true;         }     } else {         if (!include(CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'bootstrap.php')) {             $failed = true;     ...