Thursday, May 05 2016

Create Multiple Database Connection in Codeigniter

In this post we have explained about how to create multiple database connection in codeigniter. Please do the following changes in your files.

Config.php:

Change the below following things in your config.php

$active_group = 'default';
$active_record = TRUE;

Read More

Monday, April 25 2016

How to Prevent SQL Injection in PHP

We had published after long time back article about SQL injection. First of all explain what is sql injection.To avoid the unwanted peoples are access your database without your knowledge i.e hacking.When the system (website) to ask the input from users in that time we won’t directly pass the input to the database we must validate the inputs.

Following things are to prevent the user input :

If you got the input from users, you have to validate using regular expressions for example.

Read More

Friday, April 22 2016

Custom order by query by field name in mysql

In MySql select query we can customize the order of display the result as our wish. The following query I hope it will give some clear ideas do more thoughts in your future queries.

For example:

SELECT * FROM users_ranking 
ORDER BY field(rank_position,'1','2','3','6','4','5'),email ASC

 

 

Friday, April 22 2016

SQL Insert into Select Query Example

Guys you are trying to insert data from one of your existing table to another existing table or same table in mysql you can use SQL Insert into Select Query. The following query will explain

INSERT INTO users (user_id,username,email,password)
SELECT user_id,username,email,password FROM users;

You can add where clause too,

INSERT INTO users (user_id,username,email,password)
SELECT user_id,username,email,password FROM users
Where user_id <= 5;

 

Monday, April 18 2016

How to Generate Strong Password in PHP

In this post we have explained about how to generate strong password in PHP. Following function is very easy to generate strong password with alphanumeric and custom special characters too.

generate_strong_password_in_php

Read More

Sunday, April 10 2016

How to Upload Image With Custom Resize in PHP

In this article we have explained about how to upload an image with resize using simple php script. Save image as your width and height.

In HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
		<title>Upload Image File and Resized</title>
		<style>
			.success{
				color:green;
			} 
			.error{
				color:red;
			}
		</style>
	</head>
	<body>
		<form enctype="multipart/form-data" action="" method="post">
			<input type="file" name="files" />
			<input type="submit" value="Upload File" name="upload"/>
		</form>
	</body>
</html>

Read More

Friday, April 08 2016

How to Create Custom Helper in Codeigniter

In this  article we have explained about how to create custom Helper in Codeigniter. Helper is a group of functions but it is not a class.

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

if ( ! function_exists('sample_method'))
{
    function sample_method($var = '')
    {
        return $var;
    }   
}

Read More

Sunday, April 03 2016

Predict illegal words from the content in codeigniter

To avoid the illegal words in your content as you are using codeigniter provide word_censor functions.Here we are brief explain about this function. First you mention what are the words are you going to skip from the content. Those values are maintain your table.

Table:

CREATE TABLE `test`.`get_illegal_words` (`word_id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, `illegal_word` VARCHAR(255) NOT NULL) ENGINE = InnoDB;

Read More

Sunday, April 03 2016

Get latitude and longitude values from your address

When you are integrating google maps for locations you may need to know their latitude and longitude values. In that time pass your address through maps.google.com for api request.It returns the values as json output. The values are stored into database. So next time you can search the location in table. If it is not found you can send api request and store it.Why we are store the values in database because to avoid of frequent usage this is free api even it has some limit of access. when we frequent request the server doesn’t respond immediately. So that’s why we store the values.

In php:

For example

$prepAddr="Atlanda";

$geocode=file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$prepAddr.'&sensor=false');

$output= json_decode($geocode);

$lat = $output->results[0]->geometry->location->lat;
$long = $output->results[0]->geometry->location->lng;

Database:

CREATE TABLE `test`.`geocode` (`location_id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, `city_name` VARCHAR(255) NOT NULL, `latitude` VARCHAR(255) NOT NULL, `longitude` VARCHAR(255) NOT NULL, `status` TINYINT(2) NOT NULL DEFAULT '1' COMMENT '1-Active,0-Deactive') ENGINE = InnoDB;