PHP Frameworks Archives - Page 9 of 13

MySQL | Unable to create foreign key between two tables

Author - Webner

We have two tables say table1 and table 2. In table 1, there is a field named Id and this field is set as primary key in table 1. We want to use it as foreign key in table 2.

Fields in both the tables:
Table 1
Id Read more…

MySQL | How to support European characters on database level

Author - Parminder Kaur

European characters like è é å ñ ü ,à, è, ì, ò, ù – À, È, Ì, Ò, Ù, ™, © ,• , ∑, α, β, «, » do not get inserted correctly in MySQL by default. To fix it, we need to change the character set (fixed collection of symbols) and collation (set of rules that determine how data is sorted and compared).

To insert and retrieve european characters change character set to utf Read more…

MYSQL | #1293 – Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP

Author - Ishpreet Kaur

Suppose we want to have columns created_date and last_modified_time with default timestamp in any table in MySQL/Phpmyadmin.

Let us take an example of Students table.

Create table Students using following query :
CREATE TABLE students(
first_name varchar(20) NOT NULL,
last_name varchar(20) NOT NULL Read more…

CakePHP | How to implement Internationalization in CakePHP 3.X

Author - Rita

To implement Internationalization, CakePHP will pick all your strings which start with “__(“ double underscore ) and generate a default file for you.

For Example: one of the strings defined in our project is as below:
echo __ ( ‘ Gift Cards Not available’ );
Replace all your normal string with (__ Read more…

PHP | Convert Special Characters to HTML entities without using htmlspecialchars( ) function

Author - Kritika Sood

We can’t use special characters like >,<,”,’ etc directly in code because browser mixes these characters with HTML tags and gets confused. So we can use HTML entities if we want to use special characters in our code.

Below are some common entities which we can use Read more…

How to access javascript array in php on submit

Author - Kritika Sood

Suppose you have a Javascript array and want to send it to the server side on page submit then you can use this method.

Suppose we have a Javascript array with 3 elements:
var test = [“test1”, “test2”, “test3”];
Now create a hidden variable in HTML. This variable will Read more…

PHP – Possible reasons of “Allowed memory size exhausted” error

Author - Rita

Most of the times when we get memory exhausted error, we normally think that the memory allocated for php program execution in php.ini file is not sufficient and raise this limit to try to fix the error.

However, code inefficiency could be the reason behind the error. Some examples Read more…

How to add combobox in editable datagrid using jQuery EasyUI

Author - Webner

Following is the code to add Combobox in editable data grid:

<table id=”dg” title=” Combobox in editable datagrid ” style=”width:100%;height:700px”
toolbar=”#toolbar” pagination=”true” rownumbers=”true” fitColumns=”false” singleSelect=”true” autoSave=”true” data-options=”pageSize:50″>
&lt Read more…

PHP | Adding text over an image

Author - Richa

In order to add text over an image, following PHP code can be used. Read the comments to understand purpose of code statements:

header (“Content-type: image/jpeg”); //setting the content type

//variable containing the string to be written on the image
$txt = “Here goes the text to Read more…

PHP | better way to include a file

Author - Kiran Preet

Have a look at this folder structure:


Now in Abc.php file, try to include Qwerty.php using the following code:
It will give this error:

Fatal error: Failed opening required Read more…

PHP | How to install CakePHP 3.0

Author - Deepika

These are the steps to install CakePHP 3.0 on Ubuntu machine:

Make sure you have PHP 5.5.9 (CLI) or higher installed. Check php version on your system using this command:

php -v

Run the following commands:

1. Download the composer installer in your Read more…

Introduction to Heroku

Author - Webner

Heroku is an all-in-one cloud based platform which allows software developers to develop and host applications over Heroku cloud. The company was setup in June 2007 which initially supported Ruby programming language. Later on, support for other programming languages such as Node.js, Java, PHP, Python, Scala, Go Read more…

How to send iCal attachment in the email

Author - Kailash

Suppose you are sending an email in PHP and want to send iCal attachment. In PHP this can be achieved as below:

1. Create iCal file content and put in a variable (like $iCal here):

X Read more…

Salesforce | Please use TLS 1.1 or higher when connecting to Salesforce using https

Author - Ashish

Salesforce login via PHP Salesforce Toolkit API may throw this exception:

Please use TLS 1.1 or higher when connecting to Salesforce using https

The reason is Salesforce has provided customers with the Critical Update feature Require TLS 1.1 or higher for HTTPS to maintain high Security. If you Read more…

How to access Moodle files outside the Moodle?

Author - Shalini

We can access Moodle outside the Moodle (without login) by passing token in the URL.

For example :


If token is not be passed into the URL, then it redirects to Moodle’s Read more…

CakePHP bake: SQLSTATE[42S02]: Base table or view not found

Author - Rita

While running cake bake command for cakephp 3.0 we got the following error:

SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘tablename .columnname’ doesn’t exist

The culprit was a column with name test_id in one of the tables. As per bake command’s conventions about foreign Read more…

Heroku | Change PHP session timeout

Author - Webner

In Heroku, there is no way to change HTTP session timeout (or some other php.ini settings) from user interface. For this create a file with name .user.ini and specify the properties in it. This file is to be created in root folder of project.

In our case we Read more…

CakePHP | Redirect from http to https URL

Author - Kailash

If you want to redirect from http to https in CakePHP, generally redirect method code is like this:
$this­->redirect(array(“controller” => “myController”,”action” =>t; “myAction”));
But if your site is running on http protocol it will redirect to the url with http protocol:

‘http://www Read more…

Moodle and Java | Retrieving users’ data from Moodle using External Java Application

Author - Richa

Retrieving users’ data from Moodle using External Java Application

We can write a basic REST moodle client code using Java to fetch users’ records from moodle. Before writing the code, you need to perform below steps in Moodle which are required in order to fetch the data:

1. Create external Read more…

Curl | How to test a Restful web service using curl

Author - Rita

Let’s consider, we have a demo Restful service (created in Java Spring here but you can create in any language) to login user which accepts username and password as input and returns Success/Failure in response.

Request Object : Demo Login Request class :

Response Object :

Here is how to call Read more…