How to fetch multi-lingual content from database

The basic purpose of this post is to guide you all about fetching multilingual content from database.
I mean to say that, if you have stored japanese text in your database, So in order to fetch the japanese content , you need to set the character encoding to UTF-8 format, while communication with the database for fetching the result.

In Case of MYSQLi

query(“SELECT ColumnName FROM tableName “)) {
printf(“Select returned %d rows.\n”, $result->num_rows);

/* free result set */
$result->close();
}
$mysqli->close();
?>

In case you are using multiple database

If you don’t pass in “true” to mysqli_connect() in the example below, $link1 and $link2 will have the same resource id# and both database connections will end up being set to utf-8 charsets.

How to use FCKeditor in symfony

1. Download the FCKeditor source from http://ckeditor.com/download

2. Extract the source to /web/js/ directory of your symfony project directory

3. To use the editor in symfony, add (edit if present)the below line //config/settings.yml

.settings:
rich_text_fck_js_dir: js/fckeditor

4. You have to edit /web/js/fckeditor/fckconfig.js

var _FileBrowserLanguage = ‘php’ ; // asp | aspx | cfm | lasso | perl | php | py
var _QuickUploadLanguage = ‘php’ ; // asp | aspx | cfm | lasso | php

Depending on the technology you are using you have to set the above two parameter

5. In newer versions of FCKEditor you also have to enable the PHP connector in file /web/js/fckeditor/editor/filemanager/connectors/php/config.php on line 28, and also set your upload directory (on line 32).

$Config[‘Enabled’] = false;
$Config[‘UserFilesPath’] = ‘/uploads/assets/’ ;

You can set the UserFilesPath to whatever folder you want to store the uploaded file

6. Now you are ready to use the fck editor in your page

$options = array(
‘rich’ => ‘fck’,
‘height’ => 500,
‘width’ => 500,
);
echo textarea_tag(‘inputname’, ‘Lorem ipsum’, $options );

Thats All 🙂

Update query in symfony

Suppose you want to execute query like
UPDATE tableName SET column1 = ‘abc’,column2 = ‘xyz’ WHERE column =’1′;
then you can use the below syntax to do so 🙂

—————————————————————————-

$con = Propel::getConnection();

/* Here you have to set the condition for which you need to update */
$c1 = new Criteria();
$c1->add(TableNamePeer::COLUMN_NAME, $conditionForColumn1);

/* Here you have to set the column value */
$c2 = new Criteria();
$c2->add(TableNamePeer::COLUMN_TO_UPDATE, $value);

BasePeer::doUpdate($c1, $c2, $con);

How to set the meta tag information intemplate file in symfony

You can set the meta tag information in your template file as below.

sfContext::getInstance()->getResponse()->setTitle(‘Your meta title here’);
sfContext::getInstance()->getResponse()->addMeta(‘description’,’ Meta description information’);
sfContext::getInstance()->getResponse()->addMeta(‘keywords’,’meta tag keywords seperated by commas’);

That’s it.

Thanks

How to convert bitmap image(.jpg , .jpeg, .gif, .png) to vector format (.ai , .eps, .svg)

For converting bitmap image to vector image you need to have autotrace library installed .

If you not installed you can install that bu using the command “yum install autotrace”.

Follow the instruction step till the installation is complete.

Once its installed you can use the below command to convert the image to vector format.

$ autotrace testInputImage.png -output-file testOutputImage.svg

Other example :

$autotrace –input-format=jpg –output-file=tshirt.ai –dpi=1024 –color-count=256 –despeckle-level=0 –despeckle-tightness=0 –corner-always-threshold=60 –line-threshold=0.1 –width-weight-factor=0.1 –line-reversion-threshold=0.1 –preserve-width –remove-adjacent-corners tshirt.ai 2>&1

and your are done.

For more information and option visit http://autotrace.sourceforge.net

Thanks

GD support

How to check if GD support is enabled or not.

<?php
var_dump(gd_info());
?>

If GD support is enabled then you will get an array in that you will get “GD Version”.

If you didn’t get this that means GD support is not there .

To enable GD support you should install
GD library by the below command
“yum install php-gd” (Fedora Linux)
This will install GD support.

Now when you check the output of the above php code it will display the GD version

How to establish oracle database connection in php

First of all you need to check whether “oci8” support is enabled or not, if not you have to enable that you can check this in your phpinfo file.

Once this is done.

Now in you test.php file

You have to explicitly set the ORACLE_HOME and LD_LIBRARY_PATH path.
This information will be available in you phpinfo file.

The “$dbstr” variable information you can find it from your “tnsnames.ora” file .

Test.php start

—————————————————————————————–

if (!ini_get(‘display_errors’)) {
ini_set(‘display_errors’, 1);
}
PutEnv(“ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/”);
PutEnv(“LD_LIBRARY_PATH=-Wl,-rpath,/usr/lib/oracle/xe/app/oracle/product/10.2.0/server//lib -L/usr/lib/oracle/xe/app/oracle/product/10.2.0/server//lib -lclntsh”);

$dbstr =”(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.XX)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = YOURDATABASENAME)
)
)”;

if(!@($conn = oci_connect(‘DBUSERNAME’,’DBPASSWORD’,$dbstr)))
{
print_r(ocierror());

}
else
{
echo “connected succesfully”;
}

—————————————————————————————–

Thanks

How to import data into mysql db from sql file

Open your shell prompt

navigate to the mysql directory (default is /var/lib/mysql)
cd /pathToYourMysqlDirectory/

then type the below command

$ mysql -u mysqlUserName -p Password -h HostName DatabaseName < /loactionOfYourSqlFile/yourSqlFileName.sql

Where
mysqlUserName = Mysql User Name
Password = Mysql User Password
HostName = Mysql Host Name (This could be local host or some remote IP where you want to import the database)
DatabaseName = Mysql Database Name
/loactionOfYourSqlFile/yourSqlFileName.sql = This is the location of your sql file

Note : This is work only in Linux system

Thanks