How to use multiple MySql database in PHP, MYSQLi & PDO

Here in this tutorial I'm going to explain how you can connect multiple mysql databasees using PHP and how can you query with multiple database connections in PHP.
Here we have single instance with multiple database connections.

If you are going to use MYSQLi with PHP you can create multiple connections like below. Here we have 2 database connections.

Here we are querying with same table names but with different databases.

If you are going to use PDO with PHP then you can create database connections like below.

Here is the way to querying with same table names but with different databases using PDO.

  ...  Read More

Share This:

RESTful API in PHP | Developing REST api in core php | Memcache in php | Restful web services in core php example | RESTful API example in PHP

PHP REST API backed up with a MySQL database is a very common schematic of an Enterprise mobile application.

The most important concept in REST is resources, which are identified by global IDs — typically using URIs. Client applications use HTTP methods (GET/ POST/ PUT/ DELETE) to manipulate the resource or collection of resources. A RESTful Web service is implemented using HTTP and the principles of REST.


HTTP methods are mapped to CRUD (create, read, update and delete) actions for a resource. Although you can make slight modifications such as making the PUT method to create or update, the basic patterns are listed as follows. ...  Read More

Share This:

Some Javascript and PHP tricky question & answers

8 + true == 9

In JavaScript, when the plus operator is placed between a number and a boolean, the boolean is converted to a number.

Like false == 0 and true == 1. So 8 + true is converted to 8 + 1 and thus we get the answer of 9.

true + false = 1

These above 2 operations will give same result in PHP and other languages as well.

'8' + 8 = 88

true + '7' = true7

1 + 1 + '1' = 21

-'60' + 60 = 0

What if we attempt to negate a string and then add a number? As you should know by now, without the negation, our answer would be '6060'. However, the negation changes things. ...  Read More

Share This:

How to Generate Barcode using PHP | How to read barcode and save it in php & mysql

Are you looking for the code of scanning bar codes in PHP ? Here is the article for that. In this article I'm writing the PHP code to generate the bar code and explaining how you can read the bar code through the bar code scanner.


Using barcode scanner :

Put your cursor into the text box and connect your scanner USB to your CPU or laptop then scan the barcode. This will read the barcode and will fill the value in text box and the you can submit the form and save the data in database. ...  Read More

Share This:

Email invoice in PDF | Generate PDF in Laravel | MPDF

So many time we need to send our invoices or reports in pdf. Here I'm going to explain how to generate the pdf in Laravel. You will also learn that how to send pdf in email attachment in Laravel. Here we will be creating a dynamic view page or HTML page and then will convert that html page to pdf.

Because we are creating the pdf file in Laravel so we need to install Laravel first and here is the link to let you know how to install the Laravel.

Install Laravel:
Install laravel

I'll be generating the PDF using MPDF library. So first of all we need to install mpdf using below command. I have use 6.1 version you can change it according to your need. ...  Read More

Share This:

Stripe | Register user on stripe in Laravel PHP | Create subscription plan | Plan subscription | Charge payment | Stripe payments in Laravel and PHP

Stripe is the beautiful payment gateway which allow you to accept payments from your customers easily and securely. Stripe also allows to transfer payments from bank to bank. We can create recurring payments through the Stripe. We can create subscriptions for the users through the Stripe API. You can do adaptive payments through the Stripe. For example If customer pat $100 than you can split this payment to multiple users like you can give 30% to cab driver and rest for the Admin.

In this article I'm going to explain followings: ...  Read More

Share This:

How to update php 7 on OSX

Open your terminal and run following commands:

1) brew update 2) brew install homebrew/php/php70 3) sudo apachectl stop 4) sudo apachectl stop 5) export PATH="$(brew --prefix homebrew/php/php70)/bin:$PATH" 6) php -version

Share This:

How To Block Multiple IP Addresses using PHP

If you have measured some suspected IP address don't worry you can restrict those IP addresses in PHP. Those IP will not be able to access you website.

Here I have created a text file where all the block ips has been written.  And I also have created blocked IPs array. I will get the client IP and then will check the blocked list of IPs if user IP exist in the blocked IPs array then will show the message on website.


Share This:

Block IP Address from accessing your website using .htaccess

Here we learn how to block IP address in PHP. Now here is another example of blocking the IP address for accessing the website by .htaccess file.


Share This:

Php code to create php file and write php code into that file

Make sure file a.php should be writable

$filename = 'a.php';
$phpcode = "<?php
\$arr[] = array('2','3','4');
\$var2 = 5;
echo \$var=\$var2;
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
// Write $somecontent to our opened file.
if (fwrite($handle, $phpcode) === FALSE) {
echo "Cannot write to file ($filename)";
} else {
echo "The file $filename is not writable";

Share This: