phpLens
 home  products examples manual  faq support forum  contact news  login store

This FAQ is actually two phpLens objects.

-What is required to run phpLens?
Which web-hosting sites support Zend Optimizer?
-What databases are supported by phpLens?

Programming Problems
How do i configure a URL that edits or searches or creates a new record?
When I click on a url, I want reset a phpLens object to its original state.
I want to synchronize the sql of a two phpLens objects so that the 2nd object has the same sort order.
I would like to be able to print out a report from the grid.
How do I update/insert into multiple tables?
I am using Smarty and it conflicts with the Smarty defined in phpLens
I am running a load balancer in front of my web servers. Generating Excel/CSV files is server specific, so currently the Excel file can be generated on server 192.168.0.10, but the load balancer redirects the download to another server. How do I handle this scenario?
How do I apply CSS to an input field.
How do i click on a row in the grid, and switch to EDIT mode immediately.
Why can I declare PHP global variables in lookupLens sql but not in powerLens PHP code?

Installation Problems

Installation problems - here is a checklist to try...
-Why do i get rubbish characters when I run testphplens.php or testtext.php?
Parse error: parse error in ./phplens-main.inc.php on line 11
-How do I connect to a database?
-Why am i getting this message: "PHPLens and Sessions are using the same connection, but they are connected to different databases. Please change PHPLens userid or session userid to force different connections" ?
- I'm getting the following warning message: "Warning: session_start() [function.session-start]: open(/tmp\sess_f5aa5c2a8921815b57113d6f7d744024, O_RDWR) failed: No such file or directory (2)"
- The gridbuilder works, but the applet builder does not.

 

-What is required to run phpLens?

PHP 4.06 or later and the Zend Optimizer, and of course a database such as MySQL or Oracle. PHP4 sessions must be enabled. We have tested phpLens on Linux and Windows 2000/NT/98, and with Apache, IIS and PWS.

Earlier versions of PHP might work, but we do not support it.
100

Which web-hosting sites support Zend Optimizer?

We host at http://futurequest.net and a search on google will return many other hosting companies that support Zend Optimizer: http://www.google.com/search?sourceid=navclient&q=zend+optimizer+web+hosting
110

-What databases are supported by phpLens?

PhpLens uses a database wrapper library called ADODB developed by our technical lead. It supports Oracle, Sybase, MySQL, PostgreSQL, Informix, Interbase, Microsoft SQL Server, Microsoft Access, FoxPro, and ODBC. People using ODBC have reported successful connections to DB2 and Progress. There is also experimental Frontbase support.

ADODB is Open Source so you can adapt it to your database if it is not listed above.

The latest version of ADODB can be obtained from
http://php.weblogs.com/adodb
200


Programming Problems

 
250

How do i configure a URL that edits or searches or creates a new record?

The following applies for phpLens 2.4.0 or later. For earlier versions of phpLens, please observe the behaviour of phpLens, as the GET/POST parameters have changed over time.

We assume that your phpLens object's id is stored in a variable called $id, the current page's url is in $PHP_SELF.

(A) To configure creation of a new record.

$url = "$PHP_SELF?phplens_$id=new";

(B) To configure editing an existing record

This assumes the value of the primary key is is $key and the type (eg C or I or N) in $type.

$url = "$PHP_SELF?phplens_$id=e&lens_p1=$key&t=$type";


Optional is the rn_$id GET parameter, which holds the record number. Some legal values for $type are

'C' = char/varchar
'I' = integer
'N' = numeric/float

(C) Configuring search/filtering

This is tricky, because the parameters vary depending on whether you have check boxes enabled, popups and other options. Because of the confusing number of combinations, we recommend a trial and error approach of observing the POST parameters and copying the relevant values.

The latest versions of phpLens accept both POST/GET parameters for searches. See
http://phplens.com/lens/lensforum/msgs.php?id=2585 for more details.


Modifying Multiple Applets
Sometimes you want to modify multiple applets in one http GET. We now allow you to replace

(a) lens_p1 with lens_p1_$this->id and
(b) t with t_$this->id.

So if you have 2 applets, A and B, then to edit record 1 in A and record 2 in B, use

$url = "$PHP_SELF?phplens_A=e&lens_p1_A=1&t_A=I&phplens_B=e&lens_p1_B=2&t_B=I";

Compound Keys
When using compound keys, the values that you pass to lens_p1 are a bit more complicated. The type information and all the field values are combined into one.

Suppose your key consists of 2 values, defined in $lens->keyCompound = 'NAME;AGE'. NAME is a char field, and AGE is an integer field.

The lens_p1 value can be generated using the LensPackKeys function (available when you include phplens.inc.php - the source can be found in phplens-common.inc.php).

$name = 'Jill';
$age = 43;
$lens_p1 = LensPackKey( array('C-'.$name,'I-'.$age) );

$lens_p1 will hold:

.C-Jill.I-43.

Basicly each element of the array is a string that begins with the 1-char metatype, followed by a dash (-), then the actual value. The array order must match the field order in $lens->keyCompound.
402
When I click on a url, I want reset a phpLens object to its original state.

Add to the url the following get parameter, where $id is the phpLens id.

  $url .= "?lens_$id=reset";

or

  $url .= "&lens_$id=reset";

Alternatively, in your php code use the Reset() function:

  $lens->Reset();


In 3.1 and later, you can use an alternative syntax in the url (useful when you want to delete a record, then reset the state):

  $url .= "?lens_{$id}_reset=1";

or

  $url .= "&lens_{$id}_reset=1";
403

I want to synchronize the sql of a two phpLens objects so that the 2nd object has the same sort order.

If the id of the first object is 'obj1', then look for the session variable "_lEnS_sort_obj1" which will hold an integer.
If positive, sort ascending, if negative sort descending. The absolute value of the session variable is the column ordinal position to sort on.

Eg.


$id = 'obj1'; // 1st phpLens object
$id2 = 'obj2';// copycat object

$_SESSION["_lEnS_sort_$id2"] = $_SESSION["_lEnS_sort_$id"];
# Use $HTTP_SESSION_VARS for PHP 4.0.6 or earlier

404

I would like to be able to print out a report from the grid.

That is a good point. The technique to use is to add a new navigation link called "Show All" in this example.

Then we define an overrideFunction that will override any session settings and set the pageSize. We use an overrideFunction so that any pageSize that you set in the dynamic editor will still work.

function Override(&$lens)
{
global $HTTP_GET_VARS;

if (isset($HTTP_GET_VARS['showall'])) $lens->pageSize = 999999;
}

$lensid = 'phplens_id'; ## SET YOUR OWN ID HERE

$lens->navUserButtons = "<TD bgColor=#C0C0C0><a href=$PHP_SELF?lens_$lensid=reset&showall=1>Show All</a></TD>";
$lens->overrideFunction='Override';
$lens->Render();


If you need it to display in a new window, set the target attribute in the anchor tag.
410

How do I update/insert into multiple tables?

You can update multiple tables using the spNew and spEdit procedures. This
allows you to override the default editing behaviour. For example, support
you have two tables, t1 and t1, and cols: t1.name, t2.name, t2.job


Then define (from memory - there might be syntax errors):

# call this function when creating new records
$lens->spNew = "=DoInsertInPHP({NAME},{JOB})";


function DoInsertInPHP($name,$job)
{
global $DB;
// assume you have a connection stored in $DB
// the same value is stored also in $lens->connection

$name = $DB->qstr($name); // quote variable
$job = $DB->qstr($job);

$DB->BeginTrans();
$DB->Execute("insert into t1 (name) values ($name)");
$DB->Execute("insert into t2 (name,job) values ($name,$job)");
$DB->CommitTrans();
}


Do something similar with spEdit. You might need to support delete
also with spDelete.

This requires phpLens 2.0.4 or later. If your database supports INSTEAD OF triggers,
you can do it with triggers also.
411
I am using Smarty and it conflicts with the Smarty defined in phpLens

You can modify the include in phplens-template.inc.php to point to your copy of Smarty. We do not modify or customize Smarty in any way for phpLens.
450

I am running a load balancer in front of my web servers. Generating Excel/CSV files is server specific, so currently the Excel file can be generated on server 192.168.0.10, but the load balancer redirects the download to another server. How do I handle this scenario?

In your phplens.config.inc.php file, find the line containing PHPLENS_IMG_CODE.

Modify it to contain the IP address of the server. E.g.

$SERVERIP = '192.168.0.10';
define(‘PHPLENS_IMG_CODE’, "http://$SERVERIP/php/phplens/phplens-img.php");

You will need to do this for all your application servers.
500

How do I apply CSS to an input field.

Use the new inputLens property. Say you have a CSS class called small:


<style type="text/css" media="all">
.small { font-family: Arial, Helvetica, sans-serif; font-size: 10px; }
</style>

For a given column, set:

$lens->inputLens = 'column^class=small';
590

How do i click on a row in the grid, and switch to EDIT mode immediately.

You use the rowColorLens property. See http://phplens.com/lens/lensforum/msgs.php?id=2302

Also we have the new editClick property: http://phplens.com/lens/lensman/prop/editClick.htm
600

Why can I declare PHP global variables in lookupLens sql but not in powerLens PHP code?

We allow PHP global vars in sql statements (such as lookupLens and sql properties), but do not translate in PHP code such as '=' in powerLens, colorLens, because we would have to scan your code and declare "global $var" for all your variables; this is tricky and might not work properly.

For a more detailed explanation, see
http://phplens.com/lens/lensforum/msgs.php?id=3625


601

Installation Problems

 
650

Installation problems - here is a checklist to try...

1. Read the install instructions one more time, and see if you missed out anything.

Make sure that you have set in php.ini

error_reporting=E_ALL
display_errors=1

or add the following statements

error_reporting(E_ALL);
ini_set('display_errors','1');

in your first line of code so that any errors are displayed.

2. Run testconfig.php. If there are errors, some diagnostic messages will come up, suggesting fixes.

3. Run testzendopt.php. If Zend Optimizer is not installed, you will see rubbish on the screen. Download and install Zend Optimizer from
http://zend.com/

4. Run testtext.php to see if phplens works with a text array database.

5. If you are using applets, check you file permissions in the applet directory that it is 0755 (read/write all).

6. If all of the above fail, send us a copy of your phpinfo() output, and report the results of all the above checklist items to us at support@phplens.com
690

-Why do i get rubbish characters when I run testphplens.php or testtext.php?

Sample bad output:

~~~
—€*î5qµÍÕ@¾¨«Å*ÉÚ ÉL¯ciS* 'E Id<­âkÙ™þ¼PÆÃÿ÷[Å·„›VÎý¯µ –]sèßC*f{£©ù~lu±!*v÷%L¬×X,€‘9§Ç>1©œÏ÷^Þ’=™öör‡ÿ³ùÔ7f‰²2[£qÔÄ %_0L\\M¢¨àc#ømÍÇã â«A© €Õ£j刯a=5)ç¤ýc+7ªi\\Í«[i8|i8lsÏ¥0›â+ÇÝDÑÕp6+ƍ'þ„ö_ퟞ^^ì¿9׫÷!ÊW«ª·ÎMÍgÓOoaîA]|š{=ŸU–^1×ë5ÿqy-»xïå• ìLÊíòß»Á—{òmÀ) ´oÏí‰Iþ[ÔF¶ Bôšb}ms ¦Ä›X‰Œ“˜ìsrÌ€!9TP±á‘$’0Ö ³Ì¤Ë!&æKŸî
Warning: Cannot send session cookie - headers already sent by (output started at ./phplens-main.inc.php:2) in /home/www/phplens/testtext.php on line 13

Warning: Cannot send session cache limiter - headers already sent (output started at ./phplens-main.inc.php:2) in /home/www/phplens/testtext.php on line 13

Test phpLens Setup
If images are missing, then $PHPLENS_PATH in phplens/config/phplens-config.inc.php is wrong.


There are 2 possible problems.

1. First is that you have Zend Optimizer installed, but you uploaded or unzipped the php files to your web server as text. You need to do a binary upload/unzip.

2. You do not have Zend Optimizer installed. You can test this by running phplens/testzendopt.php. You should see the message "Zend Optimizer is working!" if Zend Optimizer is installed.

You will have to download and install the Zend Optimizer from
http://www.zend.com/store/products/zend-optimizer.php

If you are using shared hosting, please contact your hosting provider and ask them to install zend optimizer.

After installing the Zend Optimizer your phpinfo() should have the following text [Also see the picture in the next section]:

This program makes use of the Zend scripting language engine:
Zend Engine v1.0.4, Copyright (c) 1998-2000 Zend Technologies
with Zend Optimizer v1.1.0, Copyright (c) 1998-2000, by Zend Technologies

If problem persists, read this guide to the Zend Optimizer: http://zend.com/store/products/optimizer-troubleshooting.php
700

Parse error: parse error in ./phplens-main.inc.php on line 11

If you get the following error below, it means that Zend Optimizer is not installed. You will have to download and install the Zend Optimizer from http://www.zend.com/store/products/zend-optimizer.php

Parse error: parse error in ./phplens-main.inc.php on line 11

Warning: Cannot send session cache limiter - headers already sent (output started at ./phplens-main.inc.php:11) in /usr/local/httpd/htdocs/xphplens/testtext.php on line 11



After installing the Zend Optimizer your phpinfo() should have the following text:

This program makes use of the Zend scripting language engine:
Zend Engine v1.0.4, Copyright (c) 1998-2000 Zend Technologies
with Zend Optimizer v1.1.0, Copyright (c) 1998-2000, by Zend Technologies


The picture for other versions of php is similar.
701

-How do I connect to a database?

A simple example of using phpLens is the following:

include('./phplens.inc.php');
session_start();
$yourID = 'someid'; // unique id for this phpLens object
$sql = 'select * from Products';
$driver = 'mysql'; // legal values include
            // postgres, oracle, mssql, access etc
$host = 'localhost';
$userid = 'userid';
$password = 'password';
$db = 'database'; // optional
$lens = PHPLensPConnect($yourID,$sql,
      $driver,$host, $userid', $password,$db);
$lens->Render();
$lens->Close();


You use the PHPLensPConnect function to connect. The $yourID variable is a unique identifier used to retrieve info from the phpLens table you created during setup. Every phpLens object you create should have a unique identifier.


For more info on PHPLensPConnect, see
http://phplens.com/lens/lensman/methods.htm
702

-Why am i getting this message: "PHPLens and Sessions are using the same connection, but they are connected to different databases. Please change PHPLens userid or session userid to force different connections" ?

I've included a new array in config/phplens.config.inc.php

'db3' => array('mysql','localhost','root','password','db3')

Here is the message I get:

PHPLens and Sessions are using the same connection, but they are connected to different databases.
Please change PHPLens userid or session userid to force different
connections.



I quote from the php manual:

http://php.net/manual/en/function.mysql-connect.php

If a second call is made to mysql_connect() with the same arguments, no new link will be established, but instead, the link identifier of the already opened link will be returned.

Also note that mysql_connect() does not connect you to the database. You have to call mysql_select_db().

So phplens will connect to mysql to get at the internal "phplens" table like this:

$conn1 = mysql_connect($host, 'root','password');
mysql_select_db($conn1, $db1);

Then your db3 code will connect with the following code:

$conn3 = mysql_connect($host3, 'root','password');
mysql_select_db($conn2,$db3);

Now my internal phpLens $conn1 is pointing to the same connection as your $conn3, but to the wrong database ($db3 when it should be $db1). This screws phplens up real bad.

The fix is to add a new user to your mysql database, and set

'db3' => array('mysql','localhost','root2','password2','db3')


Also see: http://phplens.com/lens/lensforum/msgs.php?id=561
800

- I'm getting the following warning message: "Warning: session_start() [function.session-start]: open(/tmp\sess_f5aa5c2a8921815b57113d6f7d744024, O_RDWR) failed: No such file or directory (2)"

PHP uses files to store session information. If your session directory is not setup properly you will face this problem. Modify session.save_path in php.ini, or create the appropriate \tmp directory.

Also make sure that read/write access to that directory is granted to your web-server.
801

- The gridbuilder works, but the applet builder does not.

Test the following:

1. Are you running in safe-mode. This prevent you from viewing applets you have created. This is configured in your php.ini file,

safe_mode=Off|On

2. Check your applets/objs file permissions. It should be 777 (rwx all). On Unix/Linux, try running chmod:

chmod a+rwx applets/objs
850

email: contact#phplens.com (change # to @)     telephone (malaysia): 60-3-7947 2888     fax (malaysia): 60-3-7947 2800