Tuesday, November 22, 2016

Codeigniter Transaction queries creation


Introduction on Transaction


A transaction is a logical unit of work that contains one or more SQL statements.
Transactions are atomic units of work that can be committed or rolled back.
When a transaction makes multiple changes to the database, either all the changes succeed
when the transaction is committed, or all the changes are undone when the transaction is rolled back.

A transaction begins with the first executable SQL statement.
A transaction ends when it is committed or rolled back, either explicitly
with a COMMIT or ROLLBACK statement or implicitly when a DDL (Data Definition Language (DDL) is used to manage table and index structure and CREATE, ALTER, RENAME, DROP and TRUNCATE statements are to name a few data definition elements) statement is issued.

Achieve the same in codeigniter using below code


$this->db->trans_begin();


//insert transaction
$i_data = array(
      'user_id'     => $app['opp_id']
    , 'amount'      => $app['total']
    , 'type'        => 1
    , 'feb_bal'     => 1
    , 'note'        => 'Earnings'
);

$this->db->insert('transaction', $i_data);
$tran_id = $this->db->insert_id();

//insert 2
$c_data = array(
      'oppt_opp_id' => $app['id']
    , 'status'      => 0 //closed
);
$this->db->insert('progress', $c_data);

//insert 3
$e_data = array(
      'tran_id' => $tran_id
    , 'app_id'  => $app['id']
    , 'type'    => 1
    , 'status'  => 2
);
$this->db->insert('earn_spend', $e_data);


if( if ($this->db->trans_status() === FALSE) {){
$this->db->trans_rollback();
}else{
  $this->db->trans_commit();
}

Note: To achieve the transaction statements all tables engine should be in innodb

How To Control WordPress User Permissions Effectively

To Get the access for external plugins such as AccessPress Social Share, Contact Db for a Wordpress Editor Role User

 we could get this feature by combining below plugins
1. Members Plugin : To create different Roles
2. Adminimize Plugin : To Disable Settings tab


Creating a new Role  Using Member Plugin


  • Enable the Member Plugin in Plugins tab
  • Under Users Tab > Click on the Add New Role link
  • Enter Role name text box
  • Grant the "manage_options" Capability to given role name
  • Save the Role
  • Create One user under this Role.

Member Plugin


To Disable the unwanted links under above created user, Need to follow the below steps


  • Enable the Adminimize Plugin in Plugins tab
  • Click the Adminimize Plugin settings link. (Tab Settings > Adminimize).
  • Under MiniMenu > Menu Option > check the settings tab related Url names.


Adminimize Plugin

Friday, November 18, 2016

Get magento session variable in php page

Mage::app('admin'); //get the admin session
Mage::getSingleton('core/session', array('name'=>'adminhtml')); //verify if the user is logged in to the backend
if(Mage::getSingleton('admin/session')->isLoggedIn()){
echo "logged in";
}else{
$url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
header('Location: '.$url."index.php/admin");
exit;
}

Thursday, November 17, 2016

How to Add Disqus Comment System in WordPress


Disqus

Disqus, pronounced "discuss", is a service and tool for web comments and discussions. Disqus makes commenting easier and more interactive, while connecting websites and commenters across a thriving discussion community.
The Disqus for WordPress plugin seamlessly integrates using the Disqus API and by syncing with WordPress comments.

Disqus for WordPress

  • Uses the Disqus API
  • Comments indexable by search engines (SEO-friendly)
  • Support for importing existing comments
  • Auto-sync (backup) of comments with Disqus and WordPress database

Adding Disqus Commenting System in WordPress

Adding Disqus commenting system to WordPress is very easy. 
First thing you need to do is go to Disqus website and login or signup for a new account. 
Once you are logged in, click on For Websites link next to the Disqus logo.

On the next screen, you need to click on Add Disqus to Your Site button next to your profile pic on the top right corner of the screen.

This will take you to a signup form where you need to provide your website information. Provide the title of your blog or website and then choose a unique URL for your website on the disqus commenting system. This unique URL will be the place where you can access all your comments after you have installed Disqus on your site. Lastly choose a category for your website. Once you are done, hit the Finish Registration button.




Now that you have registered your site for Disqus commenting system, it is time to connect your WordPress site to the Disqus platform. To do this, you need to install and activate the Disqus Comment System plugin. Upon activation, go to Comments » Settings and sign in with your Disqus account.


disqus-wordpress-signin

Once you are logged in, you will be shown the site you registered for Disqus commenting system. Select the site and click on the next button to finish the set up. That’s all. You have successfully added Disqus comment system to your site.

mongodb install windows

mongodb install windows

Download the latest production release of MongoDB from the MongoDB downloads page.

Click on .msi file and follow the instructions.

mongo Db

To Start the Mongodb server

Open an Administrator command prompt. Press the Win key, type cmd.exe, and press Ctrl + Shift + Enter to run the Command Prompt as Administrator. Go to Mongo db installed directory.
sy: mongod --dbpath="path to db" --port=27017
 Example: mongod --dbpath=d:\mongodb\ --port=27017

mongod ------ Command
dbpath  --- specify the database storeing path
port --- port number default port (27017)




Connect to the Mongo Db server using command prompt

Using below command we will able to connect to mongo server from command prompt in windows

sy : mongo --port=27017
Example: "C:\Program Files\MongoDB\Server\3.2\bin\mongo.exe

Friday, November 4, 2016

MySQL to export and import an .sql file from command line

 
 

To Export & Import Mysql data using Command Line

To export

If it's an entire DB, then:
$ mysqldump -u [uname] -p[pass] db_name > db_backup.sql
If it's all DBs, then:
$ mysqldump -u [uname] -p[pass] --all-databases > all_db_backup.sql
If it's specific tables within a DB, then:
$ mysqldump -u [uname] -p[pass] db_name table1 table2 > table_backup.sql
You can even go as far as auto-compressing the output using gzip (if your DB is very big):
$ mysqldump -u [uname] -p[pass] db_name | gzip > db_backup.sql.gz
If you want to do this remotely and you have the access to the server in question, then the following would work (presuming the MySQL server is on port 3306):
$ mysqldump -P 3306 -h [ip_address] -u [uname] -p[pass] db_name > db_backup.sql

To import

Type the following command to import sql data file:
$ mysql -u username -p -h localhost DATA-BASE-NAME < data.sql
In this example, import 'data.sql' file into 'blog' database using Anil as username:
$ mysql -u anil -p -h localhost blog < data.sql
If you have a dedicated database server, replace localhost hostname with with actual server name or IP address as follows:
$ mysql -u username -p -h 202.54.1.10 databasename < data.sql
OR use hostname such as mysql.cyberciti.biz
$ mysql -u username -p -h mysql.cyberciti.biz database-name < data.sql
If you do not know the database name or database name is included in sql dump you can try out something as follows:
$ mysql -u username -p -h 202.54.1.10 < data.sql