Wednesday, November 26, 2014

Installing Memcached with WAMP

How to install memcache on wamp server

Follow below instructions
1> The first thing in installing memcached with wamp is to install the Memcached service. download here the Win 32 binary version.
2> Inside the download you will find a memcached.exe file. Extract this to C:\memcached
3> Now to install the service, open a command window and enter the following

- Install the memcached service by running:
C:\memcached\memcached.exe -d install

- Start the memcached service by running:
C:\memcached\memcached.exe -d start

- You can verify if memcached is running by executing this command (You have to see full path of memcached.exe):
C:\memcached\wmic process get description, executablepath | findstr memcached.exe

Install PHP Memcache extension (php_memcache.dll)
- If you don’t have php_memcache.dll in folder C:\wamp\bin\php\php5.x\ext, download it from here and extract into this directory.
- Open php configuration file php.ini from C:\wamp\bin\apache\Apache2.x\bin directory, and add the following line to the end of Dynamic Extensions block which lies between lines 920 and 990 roughly.

extension=php_memcache.dll

- Restart all services of Wamp Server through the system tray menu.

Testing Memcached with PHP

</?php
$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die ("Could not connect to memcache");
$version = $memcache->getVersion();
echo "version: ".$version."
";
$tempObject = new stdClass;
$tempObject->strAttr = 'Testing';
$tempObject->intAttr = 0123456789;
$memcache->set('keys', $tempObject, false, 10) or die ("Failed to save data at the server");
echo "Store data in the cache (data will expire in 10 seconds)
";
$get_result = $memcache->get('keys');
echo "Data from the cache:
";
var_dump($get_result);
?>

Monday, November 24, 2014

How to Upload New Android Apps on Google Play Store

Its very easy to upload or publish Android Apps on google play store
Follow below steps.

1. Generate APK File.
      a. Edit AndroidManifest.xml write (android:debuggable="false") in application tag
              android:debuggable="false" >
      b. Click on File -> Export -> Export Android Application -> Next -> Browse Project -> Next -> Create new keystore and select Location folder and then write File name same to your application name and click on Save -> Write Password and confirm password -> Next
      c. Fill and Write complete form Alias name, password and confirm password same as previous window. Validity years 25. First and Last Name, Organizational Unit, Organization, City or Location, Sate or Province, Country Code like "India". and click Next
      d. Browse location or Destination APK file and Click Finish

2. Create Account and Upload APK for publish Apps
     a. Buy Account on Google play store with $25
     b. Go to your Google Play Developer Console ( https://play.google.com/apps/publish/ )
     c. Near the top of the screen, click Add new application.
     d. Using the drop down menu, select a default language and add a title for your app.
     e. Type the name of your app as you want it to appear in Google Play.
     f. Select Upload APK or Prepare Store Listing to add your app's information.
     g. Browse your APK and upload

3. Compleate fill information which is show in 3 tab
     a. APK
           i. Upload APK file
     b. Store Listing
           i. Fill compleate information which show in form
                  Title, Short description, Full description, At least 2 screenshots and Max 8, screenshots, 7-inch tablet, 10-inch tablet, Hi-res icon, 32-bit PNG (with alpha), Feature Graphic, JPG or 24-bit PNG (no alpha), Application type , Category, Content rating , Website, Email , Privacy Policy and click sate.
     c. Pricing & Distribution
           i. Check countries which you want to live.
4. Select published on drop down right side up corner

Wednesday, July 23, 2014

How to Create Stored Procedure in MySql phpmyadmin with Example



How to Create MySql Stored Procedure in PHP

Stored Procedure is a group of Transact SQL statements compiled into a single execution.

For create stored procedure please see below.  Stored procedure reduces database request traffic.

Database Table

employees  table  contains  empname  and  empno

CREATE TABLE employees(id INT PRIMARY KEY AUTO_INCREMENT,
empno VARCHAR(50) UNIQUE, empname VARCHAR(50));          

connection.php
</?php

$con = mysql_connect(“localhost”, “root”, “root”);
mysql_select_db(“storedprocedure”, $con);

?>

showresult.php (Simple fetch data from database)
</?php

include(“connection.php”);

$query = “select empno, empname from employees”;
$result = mysql_query($query);

while($data = mysql_fetch_array($result))
{
                echo $data[‘empno’].’ - ‘.$data[‘empname’].’’;
}

?>

Create Stored Procedure

We are going to create stored procedures that run on our database server.
Stored Procedure name empNoName(). Just like SQL statements.

DELIMITER //
CREATE PROCEDURE empNoName()
SELECT empno, empname from employees;


Call Stored Procedure

showresult.php ( With stored procedures )
</?php

include(“connection.php”);

$query = “CALL empNoName()”;
$result = mysql_query($query);

While($data = mysql_fetch_array($result))
{
                echo $data[‘empno’].’ – ‘.$data[‘empname’];
}

?>

Create Stored Procedure for Input

We can create stored Procedure from 2 types

      1.       1st type
Insert procedure IN – Input, name and datatype.

DELIMITER //
CREATE PROCEDURE insert(IN empno VARCHAR(50), IN empname varchar(50))

INSERT INTO employees(empno, empname) values (empno, empname);

      2.       2nd type

DELIMITER //
CREATE PROCEDURE insert(IN empno varchar(50), IN empname varchar(50))

BEGIN

SET @empno=empno;
SET @empname=empname;

PREPARE STMT FROM
“INSERT INTO user(empno, empname) VALUES (?,?)”;

EXECUTE STMT USING @empno, @empname

END

Insert.php
Include(“connection.php”);
$empno = 11;
$empname = “Kamran”;
$query = “CALL insert(‘$empno’, ‘$empname’)”;
$result = mysql_query($query);

?>


Monday, October 21, 2013

Cron Job Configuration Setting Guide



Cron Job Configuration Guide

 

Cron Jobs basic setup via Cpanel.

Cron Job is use to run a piece of code on certain time interval. It can done by adding following line via cpanel->Cron Jobs:
/usr/local/bin/php /home/your-site-root-dir/public_html/cron-file.php
Wget Method
* * * * *   wget –q –O- ‘http://www.domain.com/cron.php’ >/dev/null
Note: Cron commands depend on the server configuration.

 

Cron Jobs setup via SSH

-> Login to server via SSH
-> Run cd [path-homedir] command for enter the root folder
-> Run password command
-> You will see the path for root folder (eg. /home/yoursitename/public_html)
-> Run which php
-> You see path to PHP (eg. /usr/local/bin/php)
-> Run crontab –e command
-> It will open crontab file editor
-> Make changes to this file, press I key on keyboard for insert/write mode

Monday, February 6, 2012

How to make a triangle in PHP

<\?php
for ($size = 1; $size <= 5; $size++)
{
for ($j = 1; $j <= 5 -$size; $j++)
{
echo "  ";
}
for ($j = 1; $j <= 2*$size - 1; $j++)
{
echo("*");
}
echo "<\br>";
}

?>

Friday, October 14, 2011

import csv data to mysql using php

We can import data of CSV into MYSQL via PHP using fgetcsv() function along with some file handling functions. These codes help you to import data from csv file using PHP.



Create Table in bellow formate
CREATE TABLE `users` (
  `id` int(11) NOT NULL auto_increment,
  `first` text,
  `middle` text,
  `last` text,
  `email` text,
  PRIMARY KEY  (`id`)
);

Save Bellow Code in import.php file
<\?php
$con = mysql_connect("HostName", "DataBaseUserName", "DataBasePassword");
mysql_select_db("DataBaseName");

if(isset($_POST['submit']))
{
      $fileExt = $_FILES['importData']['name'];
      $chkExt = explode(".",$fileExt);
      if(strtolower($chkExt[1]) == "csv")
      {
            $fileName = $_FILES['importData']['tmp_name'];
            $handle = fopen($fileName, "r");
            while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
            {
                   $sql = "INSERT into users(first, middle, last, email) values('".addslashes($data[0])."', '".addslashes($data[1])."', '".addslashes($data[2])."', '".addslashes($data[3])."')";
                   mysql_query($sql) or die(mysql_error());
            }
            fclose($handle);
            echo "Successfully Imported";
      }else{
            echo "Invalid File";
      }
}
?>

<\form action='' method='post' enctype="multipart/form-data">
                Import File : <\input type="file" name='importData' size='20'>
                <\input type='submit' name='submit' value='Submit'>
<\/form>


Note:- Remove "\" from html tags and php opening tags

Saturday, May 21, 2011

birth date to year calculation in php

Note:- If you want to change formate of date for example YYYY-MM-DD to MM-DD-YYYY then change in list() function parametter and pass same formate parameter end of birthday function.

<\?php
function birthday($birthday)
{
    list($year,$month,$day) = explode("-",$birthday);

    //list($day,$month,$year) = explode("-",$birthday);

    $year_diff = date("Y") - $year;
    $month_diff = date("m") - $month;
    $day_diff = date("d") - $day;
   
    if ($month_diff < 0)
    {
        $year_diff--;
    }
    elseif (($month_diff==0) && ($day_diff < 0))
    {
        $year_diff--;
    }
    return $year_diff;
}

//echo birthday("YYYY-MM-DD");

echo birthday("1982-11-10");

//echo birthday("11-01-1985");
?>