Skip to main content

Posts

Access modifier in php

Access modifier in php Restricting access to properties PUBLIC PRIVATE PROTECTED Those class properties and class methods which are set to be PUBLIC is accessed from any where in PHP script.I Access: Every where Those Class properties and class methods which are set to be PRIVATE can only be access with in the class.i.e Only the same class can access the property. Access: This class only Those class properties and class methods which are set to be PROTECTED can only be accessed in side a class and from its child class.i.e only the same class and classes derived from that class can access the property Access: This Class and sub class. public $height; protected $social_insurance; private $pin_number; $abc = new User(); /* Since $pin_number was declared private, this line of code will generate an error. Try it out! */ echo "Tell me private stuff: ".$abc->pin_number; /* Since $pin_number was declared protected, this line of code will genera...

Authorize.net payment gateway integration

Authorize.net payment gateway integration Create login key and api key to check for realtime and for sandbox. You have to fill in the customers login key and transaction key either sandbox or live. Both are different. $LOGINKEY = 'XXXXXXXXX'; $TRANSKEY = 'XXXXXXXXX'; Store all the post values into respective variables by url encoding them. $firstName =urlencode( $_POST['firstname']); $lastName =urlencode($_POST['lastname']); $creditCardType =urlencode( $_POST['cardtype']); $creditCardNumber = urlencode($_POST['cardnumber']); $expMonth =urlencode( $_POST['cardmonth']);   $padMonth = str_pad($expMonth, 2, '0', STR_PAD_LEFT);     $expYear =urlencode( $_POST['cardyear']); $cvv2Number = urlencode($_POST['cardcvv']); $address1 = urlencode($_POST['address']); $city = urlencode($_POST['city']); $state =urlencode( $_POST['state']); $zip = urlencode($_POST['zip...

An Introduction to Mocking in Python

How to Run Unit Tests Without Testing Your Patience More often than not, the software we write directly interacts with what we would label as “dirty” services. In layman’s terms: services that are crucial to our application, but whose interactions have intended but undesired side-effects—that is, undesired in the context of an autonomous test run. For example: perhaps we’re writing a social app and want to test out our new ‘Post to Facebook feature’, but don’t want to actually post to Facebook every time we run our test suite. The Python unit test library includes a subpackage named unittest.mock—or if you declare it as a dependency, simply mock—which provides extremely powerful and useful means by which to mock and stub out these undesired side-effects. Note : mock is newly included in the standard library as of Python 3.3; prior distributions will have to use the Mock library downloadable via PyPI. Fear System Calls To give you another example, and one that we...

Stored Function in SQL

Stored Function in SQL Function is mainly used in the case where it must return a value. Function can be called from SQL statements. You can have DML (insert,update, delete) statements in a function. Function returns 1 value only.  Mysql: Simple function to return cube CREATE FUNCTION `calcube`(`PID` INT)           RETURNS INT(11)           RETURN PID * PID * PID Function to return student division based on marks DELIMITER $$ CREATE FUNCTION resultRemark(mark1 int,mark2 int,mark3 int,mark4 int,mark5 int) RETURNS VARCHAR(50)           DETERMINISTIC BEGIN          DECLARE lvl varchar(50); DECLARE total int; DECLARE percentage double; SET total = mark1 + mark2 + mark3 + mark4 + mark5; SET percentage = (total*100)/500;          IF percentage >= 60 THEN          ...

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