Skip to main content

Posts

How to implement PDO in PHP

Introduction PHP PDO  Connecting to SQL: 1. new PDO("sqlsrv:Server=$servername; Database=$dbname",$username,$password); Connecting to Oracle:        1. new PDO("OCI:dbname=accounts;charset=UTF-8","username","password"); Connecting to PgSQL: 1. $db = new PDO("pgsql:dbname=pdo;host=localhost","username", "password"); Connecting to MySQL: 1. $db = new PDO('mysql:host=localhost;dbname=testdb;charset=utf8', 'username', 'password'); 2. $db = new PDO('mysql:host=localhost;dbname=testdb;charset=utf8', 'username', 'password', array(PDO::ATTR_EMULATE_PREPARES => false,                                         PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); 3. $db = new PDO('mysql:host=localhost;dbname=testdb;charset=utf8', 'username', 'password');           $db->setAttribute(PDO::ATTR_ERRMODE, PDO::E...

How to Upload file using jQuery Ajax PHP

How to Upload file using jQuery Ajax PHP Example 1: Single file upload using jQuery and Ajax Step 1: Create Html Form <form id="data" method="post" enctype="multipart/form-data">     <label>First Name :</label><input type="text" name="firstname" value="" />     <label>Last Name :</label><input type="text" name="lastname" value="" /> <label>Email :</label><input type="email" name="email" value="" /> <label>Contact Number :</label><input type="text" name="phone" value="" />     <label>Upload Profile :</label><input name="image" type="file" />     <input type="submit" value="Submit" /> </form> Step 2: Now create javascript for file uploading       <script>   $...

Internationalizing in Cakephp

Steps how to implement multiple language in Cake PHP  Step 1: Set the route configuration in app/Config/routes.php               // i.e like www.google.com/language/controller/action               Router::connect('/:language/:controller/:action/*',array(),array('language' => '[a-z]{3}'));  Step 2: Set the config language in app/Config/core.php             Configure::write('Config.language', 'eng');   Step 3: create Helper in app/View/Helper/NewHtmlHelper.php             App::uses('HtmlHelper', 'View/Helper');            class NewHtmlHelper extends HtmlHelper {                   public function url($url = null, $full = false) {     ...

Generate XML file in Cakephp

Steps to Generate XML file using CakePHP: Step-1 Enable to parse xml extension in config route.php file.     Router::parseExtensions('xml'); Step-2 Add Request Handler Component to the Controller    var $components = array(‘RequestHandler’); Step-3 Add controller Action For XML Generation in Post Controller     function generateXMLFile()     {         if ($this->RequestHandler->isXml()) { // check request type             $this->layout = 'empty'; // create an empty layout in app/views/layouts/empty.ctp              }        }  Add header code in empty layout <?php header('Content-type: text/xml');?> <?php echo $this->Xml->header(); ?> <?php echo $content_for_layout; ?> Step-4 Set up View To generate XML Create xml folder inside Posts vi...

Ajax Form Submission AngularJS

Ajax Form Submission AngularJS AngularJS is an MVC JavaScript framework which elegantly separates controller, business and model logic in your application. HTML page <!DOCTYPE html> <html> <head> <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script> </head> <body ng-app="AddUser"> <form ng-controller="AppCtrl" name="add_user">             <div class="modal-header">                 <h3 class="modal-title">Add User Form</h3>             </div>             <div class="modal-body">                 <input type="text" class="form-control" name="user_email" ng-model="user_name" placeholder="Ent...

jQuery Populate City Country Dropdown in Cakephp

Populating city Dropdown based on Country Selecting by using jQuery and Ajax. Step 1: Load the jquery library <script type="text/javascript" src="http://code.jquery.com/jquery.js"></script> Html view: <div> <label>Country:</label> <select class="country"> <option>Select</option> <option value="usa">United States</option> <option value="india">India</option> <option value="uk">United Kingdom</option> </select> </div> <div id="response">     <!--Response will be inserted here--> </div> Step 2: Call jQuery change event and fetch the ajax <script type="text/javascript"> $(document).ready(function(){     $("select.country").change(function(){         var selectedCountry = $(".country option:selected").val();         $.ajax({          ...

PHP Magic Function

PHP Magic Function The " magic " methods are ones with special names, starting with two underscores, which denote methods which will be triggered in response to particular PHP events. magic functions will never directly be called by the programmer – actually, PHP will call the function ‘behind the scenes’. List of List of Magic Methods in PHP __construct:  This magic methods is called when someone create object of your class. Usually this is used for creating constructor in php5. __destruct:  This magic method is called when object of your class is unset. This is just opposite of __construct. __get:  This method called when your object attempt to read property or variable of the class which is inaccessible or unavailable. __set:  This method called when object of your class attempts to set value of the property which is really inaccessible or unavailable in your class. __isset:   This magic methods trigger when isset() function is applied on any p...