Skip to main content

Posts

MySQL Examples for Beginners

MySQL Examples for Beginners This basic MySQL query which will help beginners to learn. -- Delete if it exists mysql> DROP DATABASE IF EXISTS databaseName -- Create only if it does not exists mysql> CREATE DATABASE IF NOT EXISTS databaseName -- Set the default (current) database mysql> USE databaseName -- Show the default database mysql> SELECT DATABASE() -- Show the CREATE DATABASE statement mysql> SHOW CREATE DATABASE databaseName  -- Show all the tables in the current database. mysql> SHOW TABLES; -- Create the table "products". mysql> CREATE TABLE IF NOT EXISTS products ( productID bigint(11) UNSIGNED NOT NULL AUTO_INCREMENT, productCode CHAR(3) NOT NULL DEFAULT '', name VARCHAR(30) NOT NULL DEFAULT '', quantity INT UNSIGNED NOT NULL DEFAULT 0, price DECIMAL(7,2) NOT NULL DEFAULT 0000.00, PRIMARY KEY (productID) ); -- Describe the fields (columns) of the "products" table mysql> DESCRIBE pro...

How to learn NodeJs in 5 steps

NodeJs Entry level Tutorial Node.js is an open-source, cross-platform JavaScript runtime environment for developing a diverse variety of tools and applications. It is a server-side platform built on Google Chrome's JavaScript Engine Follow Basic steps to run your first example Step1: Download Nodejs and install it. Step2: After installation Check NodeJs working or not a) Open Windows Command Prompt b) Execute the Command node -v. It print a version number Example: C:\Users\Sudhir>node -v Output: v6.9.2 c) Execute the Command npm -v . It print NPM’s version number Example: C:\Users\Sudhir>npm -v Output: 3.10.9 Step3: Type npm init and press enter Step4: It will ask for file name, version and description etc Step5: It will create a package.json file { "name": "nodetest", "version": "1.0.0", "description": "Hello test", "main": "index.js", "scripts": { ...

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...