Posts Tagged ‘php’

How to add MSSQL support in PHP5 cPanel CENTOS

Thursday, June 2nd, 2011

If you want to add MSSQL support in PHP5 cPanel CENTOS, follow the next steps:

1. First, we need to install FreeTDS
wget ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz
tar -zxvf freetds-stable.tgz
cd freetds-*

2. Begin the configuration process:
./configure --prefix=/usr/local/freetds --with-tdsver=8.0 --enable-msdblib --enable-dbmfix --with-gnu-ld

Note
Use tdsver=8.0 if you have SQL 2000/2005, tdsver=7.0 if you have SQL 7.0….

3. Compile FreeTDS
make && make install

4. Add the following line in the file /etc/ld.so.conf :
include /usr/local/freetds/lib

5. Run the following command
ldconfig -v

6. Add mssql to compile options of EasyApache
nano /var/cpanel/easy/apache/rawopts/all_php5
and add:
--with-mssql=/usr/local/freetds

7. Run /scripts/easyapache or build it from WHM. You don’t need to select any additional options here. Just build it. Once the build completes, you should now be able to use PHP’s MSSQL connector functions.

Note
If you are running a 64bit OS and get an error about configure: error:
Could not find /usr/local/freetds/lib64/libsybdb.a|so
then you need to do the following:


ln -s /usr/local/freetds/lib/libsybdb.so.5 /usr/lib64/libsybdb.so.5
ln -s /usr/local/freetds/lib/libsybdb.so.5 /usr/local/freetds/lib64/libsybdb.so
ldconfig -v

How to properly save diacritics in MySQL database

Wednesday, January 27th, 2010

To save diacritics in a MySQL database you have 5 steps to follow:

1. Set(create) your database with collation utf8_general_ci;

2. Set(create) your table with utf8_general_ci collation also;

3. Make sure the text fields where you’ll insert diacritics have also the utf8_general_ci collation

4. Convert your string into ‘utf-8′ using any method you like. I recommend using PHP’s multibyte functions

e.g. $my_string = mb_convert_encoding($txt, $charset, mb_detect_encoding($my_string));

where:  $my_string is the string that will be inserted

$charset is thecharset where your diacritics are included.

Check also here the Complete list of Popular character encodings

5. Before the insert query execute this query SET NAMES latin2; (if your diacritics are from one of the latin charsets)

How to detect mobile platforms with PHP?

Friday, October 23rd, 2009

If you seek to detect mobile platforms with PHP you can try the following class:

http://code.google.com/p/php-mobile-detect/

Generating a random serial in php

Thursday, July 23rd, 2009

Here is the code

<?php

function generateSerial($nr, $lenght)
{
$code=”;
for ($i=1;$i<=$nr;$i++)
{
$code = $code.substr(strtoupper(md5(uniqid(rand(), true))), 0, $lenght).’-';
}

return substr($code, 0, strlen($code)-1);

}

echo generateSerial(4,5);

?>

PEAR in cPanel

Monday, July 6th, 2009

In order to configure PEAR with cPanel you need to follow these steps:

1. In the WHM you need to be sure that you have configured Apache with PEAR.
2. If PEAR is not active in Apache go to easyApache and in Exhaustive List of Modules, check “PEAR” and compile Apache again.
3. Now, every normal user in cPanel will have the option to select the packages they want from their cPanel -> Software/Services -> PHP PEAR Packages.
4. (Additional) If an user doesn’t have the option at Step 3, be sure that in WHM -> Software -> Module Installers -> you have installed PEAR.
5. (Additional) If you get the following error:

PEAR configuration files "/.pearrc", "/usr/etc/pear.conf" does not exist

copy pear.conf from /etc/pear.conf -> /usr/etc/pear.conf