You are here » Home Tutorial phpBender Methods and Properties
phpBender Methods and Properties Print E-mail

phpBender Methods

Methods Description
php

Usage

php(codes:String, handler:Function)

Parameters
codes:String » PHP codes
handler:Function » callback function

Description
Run PHP codes

Example
These codes below show you php method usage to run PHP codes to phpBender component instance named myComp

myComp.remoteURL = "http://localhost/freebender.php";
myCodes = "$myName=\"Jonas\";"+
"$myAge=\"26\";"+
"echo \"&myResults=Hello! my name is $myName and I'm $myAge years old.\";";
myComp.php(myCodes, myFunction);
function myFunction(){
      trace(myComp.result); // output panel
      myText.text = myComp.result.myResults;
}
phpArg

Usage

phpArg(arg:String, codes:String, param:String, handler:Function)

Parameters
arg:String » arguments that will be passed into your PHP codes. Use comma (,) delimiter if you need more than 1 argument
codes:String
» PHP codes
param:String » parameters or value that will be displayed into your PHP codes by defined arguments. Use semicolon (;) delimiter if you need more than 1 parameter
handler:Function » callback function

Description
Run PHP codes with defined arguments and parameters

Example
These codes below show you phpArg method usage to run PHP codes to phpBender component instance named myComp

myComp.remoteURL = "http://localhost/freebender.php";
myArg = "$myName,$myAge";
myCodes = "echo \"&myResults=Hello! my name is $myName and I'm $myAge years old.\";";
myParam = "Jonas;26";
myComp.phpArg(myArg, myCodes, myParam, myFunction);
function myFunction(){
      trace(myComp.result);
      myText.text = myComp.result.myResults;
}
exec

Usage

exec(path:String, handler:Function)

Parameters
path:String » absolute path of your external PHP codes file
handler:Function » callback function

Description
Load and run external PHP codes file

Notes

  1. Use absolute path e.g. /home/accountname/public_html/myApplication/myCustomPHPCodes.php instead of its URL location
  2. You may use custom extensions for your external PHP codes file such as *.php, *.txt, *.swf, etc
  3. You may use or not PHP open tag <?php and PHP close tag ?> in your external PHP codes file

Example
These codes below show you exec method usage to run external file of your PHP codes to phpBender component instance named myComp

myComp.exec("/home/accountname/public_html/myApplication/myCustomPHPCodes.php", callback);
function callback(){
      trace(myComp.result);
      myText.text = myComp.result.myResults;
}
 
Example of your external PHP codes file:
<?php
      $myName = "Jonas";
      echo "&myResults=" . $myName;
?>
db

Usage

db(query:String, handler:Function, record:Boolean, encType:Number)

Parameters
query:String » MySQL queries such as SELECT, INSERT, UPDATE, DELETE, etc
handler:Function » callback function
record:Boolean » true or false, set this parameter to true for SELECT statement only to display the record set of your database query (Default value is false)
encType:Number » this parameter define the encoding type of returned data. Available encoding types are:

  1. urlencode, e.g.
    myComp.db(("SELECT * FROM table_name",handlerFunc,true);
    myComp.db(("SELECT * FROM table_name",handlerFunc,true,0);
  2. rawurlencode, e.g.
    myComp.db(("SELECT * FROM table_name",handlerFunc,true,1);
  3. utf8encode, e.g.
    myComp.db(("SELECT * FROM table_name",handlerFunc,true,2);

Returns

  1. connectStatus:Boolean » MySQL connection status; true or MySQL error
  2. queryStatus:Boolean » MySQL query status; true or MySQL error
  3. For SELECT query only with record:Boolean parameter set to true:
    • field:Array » table's field
    • fieldNum:Number » field's length
    • recordNum:Number » record's length
    • field.table_field_name:Array » database record set by field name

Description
Run MySQL queries

Notes
Required db:Properties such as dbHost, dbUser, dbPass, dbName to be defined first

Example
These codes below show you db method usage to run MySQL queries to phpBender component instance named myComp and then display the database record set into combobox named combo_cb after DELETE statement

//sets the required properties to open a connection to database
myComp.dbHost="localhost"; //database server
myComp.dbUser="root"; //database username
myComp.dbPass="root"; //database password
myComp.dbName="test"; //database name
myComp.pConnect=false; //database connection type
myComp.remoteURL="http://localhost/freebender.php";
 
myQuery="DELETE FROM guest_book WHERE id=10";
myComp.db(myQuery,deleteHandler);
 
function deleteHandler(){
      if(myComp.result.queryStatus == "true"){
            myQuery = "SELECT id as myID,first_name as myFirstName FROM guest_book";
            myComp.db(myQuery, selectHandler, true);
      }
}
 
function selectHandler(){
      if(myComp.db.queryStatus == "true"){
            for(i=0; i<myComp.db.recordNum; i++){
                  combo_cb.addItem({label:myComp.db.field.myFirstName, data:myComp.db.field.myID});
            }
      connectStatus_txt.text = myComp.db.connectStatus;
      queryStatus_txt.text = myComp.db.queryStatus;
      fieldName_txt.text = myComp.db.field;
      fieldLength_txt.text = myComp.db.fieldNum;
      recordLength_txt.text = myComp.db.recordNum;
      }
}
specStr

Usage

specStr(var:String)

Parameters
var:String » variables

Description
Use this method to escape some characters to avoid any errors, especially \ (backslash), ' (single-quote) and" (double-quote) when you are using db method for INSERT or UPDATE queries

Example
These codes show you specStr implementation to phpBender component instance named myComp

myString1 = myComp.specStr("C:\\WINDOWS");
myString2 = myComp.specStr(textField.text);
query = "INSERT INTO table(field_1,field_2) VALUES ('"+myString1+"','"+myString2+"')";
myComp.db(query, myFunction);

 

phpBender Properties

Properties Description

regid

Description
Define your serial/registration ID of phpBender component (required by Commercial License only)

Example
This code shows you regid implementation to phpBender component instance named myComp

myComp.regid = "xxxxxxxxxxxxxxx";
remoteURL

Description
Define the location (absolute URL) of phpBender PHP file on your web server (required)

Example
This code shows you remoteURL implementation to phpBender component instance named myComp

myComp.remoteURL = "http://localhost/freebender.php";
In this case, you have to type the absolute URL of your phpBender PHP file instead of its absolute path e.g. “/home/accountname/public_html/myApplication/freebender.php”.
db:Properties

Description
These properties are required to be defined before using db method.

dbHost:String » MySQL host
dbUser:String » MySQL username
dbPass:String » MySQL password
dbName:String » MySQL database name
pConnect:Boolean » connection type to MySQL database. If true it will use persistent connection; otherwise non-persistent connection will be used (Default value is false)

Example
Please refer to db method example

Your Cart

Your Cart is currently empty.

Member Area

We have 14 guests online



Need design?
Need a quote for custom project?




 

© Copyright 2007 Webito. All Rights Reserved. Use of this website indicates your agreement to the Terms of Use.