Monday 9 November 2015

Must Know PhoneGap CLIs

In order to deal with phonegap, you should be very handy with the initial command line interface of phonegap, this is one of the cool feature of  which lets you work very quickly and create apps with an ease, so I am going to write the  list of some must know commands which are very helpful while developing a phonegap app

Install Phonegap/Cordova

npm install -g cordova

Create an App

cordova create my-app

Create Platforms, which lets you run your code in different OS

cordova platform add ios
cordova platform add amazon-fireos
cordova platform add android
cordova platform add blackberry10
cordova platform add firefoxos

Remove Platforms

cordova platform rm android

Build App

cordova build
cordova build ios

Test App on Emulator

cordova emulate android

Add a plugin to your app

cordova plugin add org.apache.cordova.camera
cordova plugin add org.apache.cordova.media-capture
cordova plugin add org.apache.cordova.media

Remove a plugin

cordova plugin rm org.apache.cordova.camera

List all the plugins added in the mobile app

cordova plugins ls

Help

cordova help
cordova info

Update Platform

cordova platform update android
cordova platform update ios

Run Phonegap/Cordova app

cordova run android
cordova run ios










 

Get Started With PHONEGAP

This is an very interested blog about creating a mobile app with one of the latest and noted technology called PHONEGAP. I was wondering that when i will get a chance to create a mobile application, Everytime probably i was stuck between the discussion of native VS hybrid everytime. As a Web programmer my strength was always server side programming language which is PHP & client side languages like HTML, CSS, JavaScript & jQuery.

Every time i felt that learning android development using java is better than creating mobile app using phonegap's javascript's framework,because i felt the framework of phonegap would be little difficult to learn, then why not try out the android's java framework if you are giving the same effort for learning, also it has many supporting blogs now a days. One day i got a project from one of a client who was looking for an app to be developed using Phonegap and i was very excited to start it, and trust me it took me a little while to learn the initial things of framework, its damn easy and you can create big web based apps with an ease and with the same team which are creating web version.

So Here are the pre-requisite things which is required if you want to kick start with phonegap.
1).A Good Experience in HTML 5 tags.
2).Good Exposure towards CSS 3.
3).A Good Knowledge in Javascript Or jQuery, if you know any good javascript framework like angular or NodeJS then it will be awesome for you.
4).And a little experience about the mobile environment, mobile development life cycles etc.

Now to get Started just follow few steps and you will be ready to start.

1).Install Git.
2).Install Node Js command line tool, visit official site of nodeJs and download their tool.
3).Download & Install JDK.
4).Download Android SDK tools.
5).Download & Install Apache ANT(Download the zip File and extract it somewhere).


Now the next step is new environment variables.

1). Create the environment variable for latest jdk bin folder, in my case it was C:\Program Files\Java\jdk1.8.0_65\bin
2). Create the environment variable for latest Apache ANT bin folder, in my case I have just extracted the zip file in C: Drive and gave the path like this C:\apache-ant-1.9.6\bin
3). Now give the path of the Android SDK folder.
4). Now give the path of build-tools(folder) in the environmental variable.
5). Now give the path of tools (folder) in the environmental variable.
6). Now give the path of platform-tools (folder) in the environmental variable.
7). Now give the path of platforms (folder)

Add all the path one by one separated a semicolon


That's it now you are ready to go.

Now to make sure, everything is set, open your NODE JS command prompt and write a command "java", if it gives any info reagarding java then, the environmental variable has been set correctly.

Now we will install phonegap into our computer, to do that just write the command
npm install -g phonegap

OR

npm install -g cordova


Cordova is the latest version phonegap engine, which is a collaborated open source version of phonegap & Apache, installing the cordova or phonegap would take few minutes or may be little more which depends on your internet connection, if you have installed cordova then always the word cordova in the command lines instead of phonegap.

after this we can create our first project in phone gap as shown below.

phonegap create MyFirstPhoneGapProject

This command will create your first phonegap project in your computer.
Now to run your first phonegap project, you have to add a platform in your phonegap project folder, if you are using android phonegap then add android platform or else IOS or whatever. To add a platform in your phonegap project  you have to write the command like this.

phonegap platform add android

this command will add all pre-requisite dependency files for android app development, so that it would  be ready to go for your android phone once you launch it.

Now finally we have to run the project in a real device, so now just connect your android phone to computer, also make sure the developer options like USB debugging of your android phone is enabled. Now run a test command.

adb devices


This will show the list of mobile devices connected to the computer, if the list is empty then disconnect and connect the phone again.









Now Run your first app by running this code.

cordova run android
Or
phonegap run android

and this will install your phonegap app into your phone.

If you have not connected any phone to your computer then phonegap will run the app in the android default emulator.



Thursday 24 September 2015

Stored Procedures in MySQL

Stored Procedures in MySQL


The MySQL database supports stored procedures. A stored procedure is a subroutine stored in the database catalog. Applications can call and execute the stored procedure. The CALL SQL statement is used to execute a stored procedure.
Stored procedures can have IN, OUT & INOUT parameters, depending on the MySQL version. The mysqli interface has no special notion for the different kinds of parameters.

Usually stored procedures are not used in the PHP Development, but still its a useful option for reducing the query writing practice.

Some examples of stored procedures with different types are as follow.

IN parameter

To create a stored procedure with in parameter you can write a query like this.

CREATE PROCEDURE p(IN id_val INT)
BEGIN
INSERT INTO test(id) VALUES(id_val);
END;

Now to call the stored procedures you can do something like this.

CALL p(1);

OUT parameter

To create a store procedure with inout/out parameter you can write a query like as following.

CREATE PROCEDURE CountOrderByStatus(
 IN orderStatus VARCHAR(25),
 OUT total INT)
BEGIN
 SELECT count(orderNumber)
 INTO total
 FROM orders
 WHERE status = orderStatus;
END


Now to call the stored procedures you can do something like this.

CALL CountOrderByStatus('Shipped',@total);

if you want to execute a php code, you can write like this

<?php
$result=mysql_query("CALL CountOrderByStatus('Shipped',@total)");
?>

INOUT parameter

To create a store procedure with inout/out parameter you can write a query like as following,
INOUT exactly works like the OUT parameter

CREATE PROCEDURE set_counter(INOUT count INT(4),IN inc INT(4))
BEGIN
 SET count = count + inc;
END;

Now to call the stored procedures you can do something like this.

CALL set_counter(@counter,1);


That's it, its damn easy to go on with.


 

Friday 28 August 2015

Design Patterns in PHP

Patterns in php. Today we are going to talk about design patterns in web development, more precisely – in PHP. Experienced developers are probably familiar with this, but this article will be extremely useful for all novice developers. So, what is it – design patterns? Design Patterns aren’t analysis patterns, they are not descriptions of common structures like linked lists, nor are they particular application or framework designs. In fact, design patterns are “descriptions of communicating objects and classes that are customized to solve a general design problem in a particular context.” In other words, Design patterns provide a generic reusable solution to the programming problems that we encounter every day. Design patterns are not ready classes or libraries, that can be simply applied to your system, this is not a concrete solution that can be converted in to source code, design patterns are much more than that. They are patterns, or templates, that can be implemented to solve a problem in different particular situations.

Design patterns help to speed up the development, as the templates are proven and from the developer’s position, only implementation is required. Design patterns not only make software development faster, but also encapsulate big ideas in a simpler way. Also, be careful not to use them in wrong places in order to avoid unpleasant situations. In addition to the theory, we also give you the most abstract and simple examples of design patterns.

    “Each pattern describes a problem which occurs over and over again … and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without doing it the same way twice.” – Christopher Alexander

Sunday 2 August 2015

How to upgrade the XAMPP, without uninstalling the older version of xampp.

I have been wondering around, like how to upgrade my xampp and i was using the older version of xampp which was 5.3 which i installed some what around like 4 years ago, when i was learning the PHP at Hyderabad from Swami Naidu Sir, but its very inimical sometime to work with certain project on the localhost where you have to work with API using CURL and in my case it was not working because the module was not enabled and likewise many were not, however there was no problem with the latest versions of the xampp almost all the modules like curl are enabled already in the localhost, also i do a lot of project with the latest cms like joomla3 or frameworks like laravel where you get all the die function errors if you are not using the latest version of php, hence i decided to update my XAMPP at any cost.

Now after digging a lot of blogs and stack-overflow, i came to know about two techniques which iam going to share right now and  i hope someone will find it helpful whoever is facing the same situation.

Technique 1.

So  the first is about not removing the older version and just upgrading the php folder, so in order to do that follow the instructions given below.

Step-1: So just go to this link http://windows.php.net/download#php-5.6 and download the latest thread safe version of xampp.

Step-2: Now i assume that your xampp is in your "C" drive, so just go to your "C:/xampp" and rename the old php folder as "php_old", create a new empty folder called "php".

Step-3: Now unzip the entire files of the new thread safe version of php into the newly created php folder.

Step-4: Now in the newly created php folder search a file "php5apache2_4.dll" or "php5apache2_2.dll" copy that file and paste it in the folder "C:\xampp\apache\modules".

Step-5. Now the last  step, go to "C:\xampp\apache\conf\extra" and open the file "httpd-xampp.conf" using a text editor, here you have to edit three things.

just provide/check correct path to these variable.

#). LoadFile "C:/xampp/php/php5ts.dll"

#). LoadModule php5_module "C:/xampp/apache/modules/php5apache2_4.dll"


#). SetEnv PHPRC "\\xampp\\php".

thats it, you're done.

Step - 6: Now just restart the apache and mysql using the xampp control panel, i hope it will work, if not like it happened in case of my colleague then please follow the second technique which is written below.

Technique 2.

Step: 1. Download the latest version of the xampp which would be a ".exe" file.
Step: 2. Stop your apache and mysql services using xampp control window, now rename the C:/xampp folder to C:/xampp_old.

Step: 3. Now run the newly dowloaded .exe file of xampp.

Step: 4. Now copy all the contents of "htdocs" folder from "C:/xampp_old" to "C:/xampp".
Step: 5. No go to "C:\xampp_old\mysql\data" copy the entire content of this folder to "C:\xampp\mysql\data".
Step:6. Restart your apache and mysql services now through the new xampp control panel, thats it and your done, and you will get the working environment with the same set of files and data which was there earlier with the updated xampp version.

Thanks a lot for reading :)