Feb
18
2008
1

Simple function to parse RGB value

Here’s a simple function to parse RGB string (#00ff00) into array, so it can be used in GD functions.
Hope it can save a little time for you.


list($r, $g, $b)= parse_RGB("#123456");

function parse_RGB($color)
{
$r= hexdec(substr($color, 1, 2));
$g= hexdec(substr($color, 3, 2));
$b= hexdec(substr($color, 5, 2));
return array($r, $g, $b);
}

Written by hkai in: PHP |
Jan
29
2008
0

ADOdb connection to MSSQL

I’m using PHP 5.2.3+ADOdb to connect SQL Server on the SQL Server on same machine. My OS is Vista Home Basic.
The SQL Server version is 9.0.3042 (2005 SP2 I guess).

The working dsn is $dsn=”mssql://username:password@192.168.0.107,1433/database”;

I tried
$dsn=”mssql://username:password@192.168.0.107:1433/database”;
and
$dsn=”mssql://username:password@192.168.0.107/database”;
both won’t connect.

The ntwdblib.dll in c:\php information:
File version: 2000.80.2039.0
Product version: 8.00.2039

Written by hkai in: PHP |
Sep
14
2007
1

Install PDO, PDO_SQLITE, PDO_DBLIB, PDO_MYSQL

Recently I’m using PRADO framework for some web application development. It comes to deploy to the server side.
The server is running Debian 3.1r3

  • apt-get install php5-dev php5-mysql php5-sybase php5-sqlite libmysqlclient-dev freetds-dev
  • apt-get install make
  • pecl install PDO
  • pecl install PDO_SQLITE
  • pecl install PDO_MYSQL
  • pecl install PDO_DBLIB

At the last step, it report:
pear/PDO_DBLIB requires PHP extension “pdo” (version >= 1.0)
No valid packages found
install failed

Here’s the solution:

  • pecl download PDO_DBLIB
  • tar zxvf PDO_DBLIB-1.0.tgz
  • pecl build
  • After the build finished, it’ll try to install to /var/tmp, on my system, the files was gone after the make. so I have to build it again
  • cd PDO_DBLIB-1.0
  • ./configure
  • make
  • After the make finished, the module is locate at ./PDO_DBLIB-1.0/modules/pdo_dblib.so, copy it to /usr/lib/php5/20060613+lfs or any location that extension files should be
  • add extension=pdo_dblib.so
  • happy coding now!
Written by hkai in: Linux Debian, Linux General, PHP |
Sep
13
2007
0

PRADO Framework: The Blog Tutorial

I was following the Blog tutorial. At the Day4: Creating ListPostPage, I get this error message:

TActiveRecordException
Description

Unable to find PostRecord::$RELATIONS['author'], Active Record relationship definition for property “author” not found in entries of PostRecord::$RELATIONS.

The code: PostRecord.php:
    public $author; //holds an UserRecord
 
    protected static $RELATIONS=array
    (
        ‘author’ => array(self::BELONGS_TO, ‘UserRecord’)
    );

The solution is:
change the $RELATIONS to public:

    public static $RELATIONS=array
    (
        ‘author’ => array(self::BELONGS_TO, ‘UserRecord’)
    );

Written by hkai in: Learning Track, PHP |
Sep
07
2007
0

PRADO Howto: integrate with Dreamweaver 8

PRADO provides an extension to integrate with Dreamweaver. Here’s the steps:

  1. install the extension: find the mxp file in editors/Dreamweaver/PRADO.mxp, double click and it’ll install as extension
  2. configure dreamweaver to use the tag lib for .page file
    1. open file: C:\Documents and Settings\[username]\Application Data\Macromedia\Dreamweaver 8\Configuration\Extensions.txt
    2. change the 1st and 2nd line, add PAGE before the :
      HTM,HTML,SHTM,SHTML,HTA,HTC,XHTML,STM,SSI,JS,AS,ASC,ASR,XML,XSL,XSD,DTD,XSLT,RSS,RDF,LBI,DWT,ASP,ASA,ASPX,ASCX,ASMX,CONFIG,CS,CSS,CFM,CFML,CFC,TLD,TXT,PHP,PHP3,PHP4,PHP5,TPL,LASSO,JSP,JSF,VB,VBS,VTM,VTML,INC,JAVA,EDML,WML,PAGE:All Documents
      HTM,HTML,HTA,HTC,XHTML,PAGE:HTML Documents
    3. open file: C:\Program Files\Macromedia\Dreamweaver 8\Configuration\DocumentTypes\MMDocumentTypes.xml
    4. change the 3rd line, add page to the winfileextension and macfileextension attribute
      <documenttype id=”HTML” internaltype=”HTML” winfileextension=”html,htm,shtml,shtm,stm,tpl,lasso,xhtml,page” macfileextension=”html,htm,shtml,shtm,tpl,lasso,xhtml,ssi,page” file=”Default.html” writebyteordermark=”false”>
  3. restart dreamweaver, open a .page file and type <com:
Written by hkai in: PHP |
Aug
28
2007
0

PRADO Howto: friendly URL

If you have a signup.page, normally you’d like to access as http://localhost/index.php?page=Signup
how to make it search engine friendly?
change it to http://localhost/index.php/page,Signup would be fine.
open application.xml , in <modules> tag, add the following:
<module id=”request” class=”THttpRequest” UrlFormat=”Path” />

save it and then visit the friendly URL!

Written by hkai in: PHP |
Aug
28
2007
0

PRADO, the php application framework

I’d like to recommend an application framework for serious PHP developers: PRADO
Please find more on http://www.pradosoft.com

Written by hkai in: PHP |
Jul
20
2007
0

Too many open files

Today I encounter a serious error in my production server running Debian 3.1 with Apache 1.3, PHP 4.3
Warning: Unknown(/web_sites/doc_root/public_html/index.php): failed to
create stream: Too many open files in Unknown on line 0

The reason is linux limit the max number of opening files to 1024, and my server is hosting more than 500 virtual hosting now, and each of them opened 2 logs. So in total when the hosting is over 512 domains, it’ll reach the limit.
Run this command to see the limit:

linuxvm1:~# ulimit -n
1024

The solution: (I know you like this)
open /usr/sbin/apachectl (or apache2ctl )
add a line to it: ulimit -n 65536
restart apache:
apachectl restart

The problem should been fixed.
If you execute /etc/init.d/apache to restart, it may not work because Debian 3.1 is not using apachectl in /etc/init.d/apache
I’m not sure how to add the ulimit to it yet.

Written by hkai in: Apache, Linux General, PHP |
Jun
26
2007
0

mssql extension installation on Vista

I installed php 5.2.3 onto c:\php, but the script won’t connect to SQL 2005 through mssql extension.
The solution:
1. get the latest ntwdblib.dll from a machine which installed sql server 2000
2. put the dll to c:\php

The dll shipped with php 5.2.3 is version 7.0, and the latest is 8.0, which make the difference when connecting to a SQL 2005.

Written by hkai in: PHP, SQL Server 2005, Windows |
Nov
10
2006
0

Code Igniter: PHP Application Platform

I like this one, it’s easier to understand and code, especially the helper libraries.

http://www.codeigniter.com/

Code Igniter is an Application Development Framework - a toolkit - for people who build web sites using PHP. Its goal is to enable you to develop projects much faster than you could if you were writing code from scratch, by providing a rich set of libraries for commonly needed tasks, as well as a simple interface and logical structure to access these libraries. Code Igniter lets you creatively focus on your project by minimizing the amount of code needed for a given task.

Written by hkai in: PHP |

Powered by WordPress | Aeros Theme | TheBuckmaker.com WordPress Themes