Google

Saturday, August 30, 2008

PHP with smarty template engine installation

PHP with smarty installation is so easy....

just download the stable version of smarty package and unzip the folder and rename folder name "smarty"

and now you create four directory in your application folder

1) config
2) templates_c
3) templates
4) cache

and just create one php file and here just specify the pathe of smaty.connect.php file and all four directory path

like the pls see example below

// put full path to Smarty.class.php
require('/usr/local/lib/php/Smarty/Smarty.class.php');
$smarty = new Smarty();

$smarty->template_dir = '/web/www.domain.com/smarty/templates';
$smarty->compile_dir = '/web/www.domain.com/smarty/templates_c';
$smarty->cache_dir = '/web/www.domain.com/smarty/cache';
$smarty->config_dir = '/web/www.domain.com/smarty/configs';

$smarty->assign('name', 'MANISH');
$smarty->display('index.tpl');

now include above php file anywhere and use the smartyy template magic.

any question then pls cooment here....i will give u the answer...thanks

Connect Mysql database in php

PHP main target is to make possible build dynamic web sites.
This possibility is available by using some database system to store information and manipulate them, when system and user needs it.
On PHP a large number of database systems come by default embbed as libraries.
On this article we will learn how to use one of the most used on data handling - MySQL.
MySQL can be installed easly, by downloading EasyPHP.
This application installs Mysql on a web based version, it means that you can manage all database processes on your browser.
It allows to create databases, and tables, edit fields , backup tables system database and a large option of new features.
To access the interface that allows you to create database click with the right button of mouse on tray icon "Administration".
Right next click

MySQL MANAGER

it will open the window where you must the name of your database and next it will ask for your table name.

Check how many fields you need on your table and build it.

Now the database and table are created let´s configure the conection to the mysql server using PHP.
Remember that server is configured with an default username and password.
You can make secure by changing it at your choice.

Follows the PHP code generated to build the table

CREATE TABLE `admin` (
`id` int(11) NOT NULL auto_increment,
`username` varchar(40) NOT NULL,
`password` varchar(16) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM

and now time to connect with php this table.....

$con = mysql_connect("localhost","database usernam","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}