Pages

2 comments

Configure PostgreSQL and phpPgAdmin in WAMP

As i told earlier am trying to switch to Flex , i am trying to learn connection between PHP and Flex. When searched i got a excellent tutorial . But the problem is that it uses PostgreSQL. As i don't have any prior experience in PostgreSQL i try to install it in my Windows 7 and configure it in WAMP . I got different errors and spend almost two days in searching and using different methods . Atlast i got it right. I will try to figure out the steps i have done.
Am using
  1. PostgreSQL 9.1
  2. WAMP Server 2.0e
  3. phpPgAdmin 5.0.2
WAMP consists
1. Apache Version :2.2.17  
2. PHP Version :5.3.5 
3. MySQL Version :5.5.8
First install PostgreSQL , no need to install additional plugins like phpPgAdmin.
Install WAMP server where ever you need.
Download PhpPgAdmin  and unzip it to WWW folder in WAMP installation.

At this point if you try to access the http://localhost/phpPgAdmin/ you may get this error.

Your PHP installation does not support PostgreSQL. You need to recompile PHP using the --with-pgsql configure option.

This is because you need to enable two extensions.
  1.  php_pgsql
  2. php_pdo_pgsql
After enabling this extensions you may not see installed  extension in phpinfo. if you check the Apache error log you see this error
PHP Warning:  PHP Startup: Unable to load dynamic library 
'D:/wamp/bin/php/php5.3.5/ext/php_pdo_oci.dll' - The specified module 
could not be found.\r\n in Unknown on line 0

 Warning:  PHP Startup: Unable to load dynamic library
 'D:/wamp/bin/php/php5.3.5/ext/php_pdo_oci.dll' - The specified module 
could not be found. in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 
'D:/wamp/bin/php/php5.3.5/ext/php_pdo_pgsql.dll' - The specified module 
could not be found.\r\n in Unknown on line 0
Warning:  PHP Startup: Unable to load dynamic library
 'D:/wamp/bin/php/php5.3.5/ext/php_pdo_pgsql.dll' - The specified module
 could not be found. in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 
'D:/wamp/bin/php/php5.3.5/ext/php_pgsql.dll' - The specified module 
could not be found.\r\n in Unknown on line 0
Warning:  PHP Startup: Unable to load dynamic library
 'D:/wamp/bin/php/php5.3.5/ext/php_pgsql.dll' - The specified module 
could not be found
To correct this error you need to copy libpq.dll from wamp\bin\php\php5.3.5 to  wamp\bin\apache\Apache2.2.17\bin . Then try to enable PHP extension and check apache error log you will not see the error . And pgsql will be shown in Loaded extensions in http://localhost/.

Now try this http://localhost/phpPgAdmin/ and you will see the PostgreSQL server. Select the PostgreSQL and login using the deafult user "postgres" and  the password you given when PostgreSQL installed. You may not able to login. It may say "Login disallowed for security reasons." . You need to set some parameters in \www\phpPgAdmin\conf\
find
$conf['extra_login_security'] = true;
and change
$conf['extra_login_security'] = false;
and find
$conf['owned_only'] = false;
and change it to
$conf['owned_only'] = true;

Now you can login to PostgreSQL  using phpPgAdmin and work on it. You can now create database and work on it. But If you tried to export the database you will get another error

Export error: Failed to execute pg_dump (given path in your conf/config.inc.php : /usr/bin/pg_dump). Please, fix this path in your configuration and relog.

This is because you did not set the path correctly . You need to change two other parameters in config.inc.php
$conf['servers'][0]['pg_dump_path'] = '/usr/bin/pg_dump';
$conf['servers'][0]['pg_dumpall_path'] = '/usr/bin/pg_dumpall';
change these params to
 $conf['servers'][0]['pg_dump_path'] = 'C:\Program Files\PostgreSQL\9.1\bin\pg_dump.exe';
 $conf['servers'][0]['pg_dumpall_path'] = 'C:\Program Files\PostgreSQL\9.1\bin\pg_dumpall.exe';
check your PostgreSQL installation directory. Now you can export the database.

Hope this post helps to configure PostgreSQL and phpPgAdmin successfully.

6 comments

Connecting Flex 4 with AMFPHP

These days am missing this blog coz am busy with learning Flex. When i tried to connect with AMFPHP i can't find anything useful. Most of them were vague .Using the default data connectivity in Flash Builder am more confused and it's code looks complex . Atlast i found someone helpfull from adobe forum.

When i tried to implement it , it shows nothing and missing some files. When i checked the PHP file, though am not good in PHP , i found there is also something also missing. I tried and searched and corrected the files.
Here is the MXML code:

	
		
	
	
		
		
			
					
			
		
	
	
		
			
			
			
			
			
			
		
	
	
	
	
		
		
			
		
				
			
		
		
			
		
		
			
		
		
			
		
		
			
		
		
	
	
This is the PHP service class which needed to be placed in the /services folder both in AMFPHP1.9 and 2.0 versions.
<?php
  include('Employee.php');
  //amfphp1.9
  class EmployeesService
  {
      var $username = "root";
      var $password = "";
      var $server = "localhost";   
      var $port = "3306";
      var $databasename = "fb_tutorial_db";    
      var $tablename = "employees";
      var $connection;
      public function __construct()
      {
          $this->connection = mysqli_connect($this->server, $this->username, $this->password, $this->databasename, $this->port);
      }
      
      public function getAllEmployees()
      {
          $stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename");
          mysqli_stmt_execute($stmt);
          $rows = array();
		  $row = new Employee();
          mysqli_stmt_bind_result($stmt, $row->emp_no, $row->birth_date, $row->first_name, $row->last_name, $row->gender, $row->hire_date);
          while (mysqli_stmt_fetch($stmt)) {
              $rows[] = $row;
              $row = new Employee();
              mysqli_stmt_bind_result($stmt, $row->emp_no, $row->birth_date, $row->first_name, $row->last_name, $row->gender, $row->hire_date);
          }  
          mysqli_stmt_free_result($stmt);
          mysqli_close($this->connection);
          return $rows;
      }
      
      public function getEmployeesByID($itemID)
      {
          $stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename where emp_no=?");     
          mysqli_bind_param($stmt, 'i', $itemID);  
          mysqli_stmt_execute($stmt);
		  $row = new Employee();
          mysqli_stmt_bind_result($stmt, $row->emp_no, $row->birth_date, $row->first_name, $row->last_name, $row->gender, $row->hire_date);
          if (mysqli_stmt_fetch($stmt)) {
              return $row;
          } else {
              return null;
          }
      }
      
      public function createEmployees($item)
      {
          $stmt = mysqli_prepare($this->connection, "INSERT INTO $this->tablename (birth_date, first_name, last_name, gender, hire_date) VALUES (?, ?, ?, ?, ?)");  
          mysqli_stmt_bind_param($stmt, 'sssss', $item["birth_date"], $item["first_name"], $item["last_name"], $item["gender"], $item["hire_date"]);
          mysqli_stmt_execute($stmt);
          $autoid = mysqli_stmt_insert_id($stmt);
          mysqli_stmt_free_result($stmt);
          mysqli_close($this->connection);
          return $autoid;
      }
  }
?>
Here is the PHP Value Object Class
<?php
class Employee{
	public $emp_no;
	public $first_name;
	public $last_name;
	public $gender;
	public $hire_date;
	public $birth_date;
}
?>
For AMFPHP 2.0 edit the endpoint from http://localhost/amfphp/gateway.php to http://localhost/amfphp2/ (version AmfPHP 2.0 )
And need to change the  createEmployees($item) function in EmployeeService.php to

  public function createEmployees($item)
      {
          $stmt = mysqli_prepare($this->connection, "INSERT INTO $this->tablename (birth_date, first_name, last_name, gender, hire_date) VALUES (?, ?, ?, ?, ?)");  
          mysqli_stmt_bind_param($stmt, 'sssss', $item->birth_date, $item->first_name, $item->last_name, $item->gender, $item->hire_date);
          mysqli_stmt_execute($stmt);
          $autoid = mysqli_stmt_insert_id($stmt);
          mysqli_stmt_free_result($stmt);
          mysqli_close($this->connection);
          return $autoid;
      }
I don't know the reason but it worked for me. But i think in 1.9 the object passed to PHP function is an array and in 2.0 it's an object of stdClass. That's why this change. 

0 comments

Honey and Bee

Honey and Bee by logicmania-lab
Honey and Bee, a photo by logicmania-lab on Flickr.

It's a sunny day. Bee's were busy with there breakfast. They were stealing honey from my rose

3 comments

Font embedding in Flash cs5

When i switched to Flash CS 5 am always confused with font embedding in Dynamic Textfield. It's different from CS4 and also not simple. So i am trying to list out the methods i used to embed fonts in flash CS

Method One
It's used to embed fonts for single or similar type of textfields. If the textfields were using same font and format this is effective. To do so first select the TextField and goto the properties panel.


select the embed button . It will open embed window. select the glyphs needed.

In this method any additional code is not needed.

Method Two
If you tried to embed same font with different textformat using the above method , most probably the format will not be applied. To solve this the subset of the fonts should be embedded and need format textfield using TextFormat.

The code looks like this:

var format:TextFormat = new TextFormat();
format.font = "Helvetica";
format.bold = true;

var format3:TextFormat = new TextFormat();
format3.font = "Helvetica";
format3.bold = true;
t2_txt.embedFonts=true;
t2_txt.defaultTextFormat = format;
t3_txt.defaultTextFormat = format3;

t1_txt.text = "Hello World 01 *";
t2_txt.text = "Hello World 01 *";
t3_txt.text = "Hello World 01 *";

Method Three
The third method of embeding font is to load from external swf file. In this method Fonts added as a subclass of Font class . The embed fonts must be export for Actionscript.

The fonts will be loaded to an external swf and it will be loaded in runtime. The exported class should registered using Font class.
import flash.text.Font;
Font.registerFont(Font1);

In main movie the code looks like this
import flash.display.Loader;

function onLoaded(e:Event):void
{
 var embeddedFonts:Array = Font.enumerateFonts(false);
 for (var i:Number = 0; i < embeddedFonts.length; i++)
 {
  var item:Font = embeddedFonts[i];
  trace("[" + i + "] name:" + item.fontName + ", style: " 
                     + item.fontStyle + ", type: " + item.fontType);
 }
 var t1_txt:TextField=new TextField();
 addChild(t1_txt);
 t1_txt.x=20;
 t1_txt.y=100;
 t1_txt.embedFonts = true;
 var format:TextFormat = new TextFormat();
 format.font = "Helvetica";
 format.bold = true;
 t1_txt.defaultTextFormat = format;
 t1_txt.text = "hello world 01 *";
 //
 var t2_txt:TextField=new TextField();
 addChild(t2_txt);
 t2_txt.x=20;
 t2_txt.y=200;
 t2_txt.embedFonts = true;
 var format2:TextFormat = new TextFormat();
 format2.font = "Helvetica Light";
 t2_txt.defaultTextFormat = format2;
 t2_txt.text = "hello world 01 *";
}

Any way textfields in stage are not working properly. I think the problem is it will instantiate before the font is loaded.


I have attached my source here. while embedding the glyphs, select the required ones. Otherwise it will affect the size of the movie.

 These are not the complete list . It's not an expert opinion . And it's about Flash CS5 and not Flex . In Flex there is embed tag which is used to embed fonts.  These are the methods used by myself for dynamic font embedding.  Hope some people will contribute their experiances also to this.

0 comments

Tapioca Leaf

Tapioca Leaf by logicmania-lab
Tapioca Leaf a photo by logicmania-lab on Flickr.
I lost my Account details . I created new account and uploaded .