php-general Digest 11 Nov 2006 12:33:36 -0000 Issue 4453

Topics (messages 244486 through 244492):

Re: Staff log-in
        244486 by: Daevid Vincent
        244491 by: Jochem Maas

PEAR and MDB2
        244487 by: Alain Roger

Re: MDB2 simple test
        244488 by: Alain Roger
        244489 by: Alain Roger
        244490 by: Alain Roger

MDB2 and PostgreSQL
        244492 by: Alain Roger

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        php-general@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
> -----Original Message-----
> From: Google Kreme [mailto:[EMAIL PROTECTED] 

Is that *really* your name?! :)

> The trouble comes when you  
> need to time-out a session because someone never logged out  
> properly.  That can be hairy.

Yeah, it's so hard to do that subtraction...

------------------------8< snip >8---------------------------
<?php
require_once('classes/user.php'); // defines a class that needs to be
de-serialized in the session.
session_start(); //this must be called at the top of every page anyways.
// user.php included above is needed so the session can instantiate the User
object.

if ( !is_bool($_SESSION['login']) || $_SESSION['login'] != true ) //we
specifically test 'true' here and boolean.
{ 
        
exit("<SCRIPT>location.href='/index.php?page=".base64_encode($_SERVER['REQUE
ST_URI'])."';</SCRIPT>");
} 
else 
{
        SQL_DB ($_SESSION['companydb']); // Connect to their default
V2_Database
        SQL_QUERY("UPDATE ".$_SESSION['companydb'].".Users SET LastAccessed
= NOW() WHERE CoreID = '".$_SESSION['coreid']."' LIMIT 1");
        
        if ((!isset($_COOKIE['sid']) && (time() - $_SESSION['last_access']
>= $_SESSION['login_timeout'])) )
        {
                echo "<script>alert('Your session has been idle for >
".$_SESSION['login_timeout']."
seconds.');location.href='./index.php';</script>";
                require_once("/your/path/htdocs/index.php");
                exit;
        }
        
        $_SESSION['last_access'] = time();
}
?>

And in case you wonder why I store the base64 of the current page, it's so
that after you authenticate them, you can gracefully pass them on to where
they were trying to go (if they weren't logged in, or had timed out),
complete with all $_GET parameters in tact...

if ($_REQUEST['page'])
        header("Location: ".base64_decode($_REQUEST['page']));
else
        header("Location: some_other_page.php");

--- End Message ---
--- Begin Message ---
Daevid Vincent wrote:
>> -----Original Message-----
>> From: Google Kreme [mailto:[EMAIL PROTECTED] 
> 
> Is that *really* your name?! :)
> 
>> The trouble comes when you  
>> need to time-out a session because someone never logged out  
>> properly.  That can be hairy.
> 
> Yeah, it's so hard to do that subtraction...

you can only forcefully log someone out if they actually make
a(nother) request - if they are logged in and then never visit the
site again then you can't actually 'log them out' [at least not using
the info stored in the relevant session file. the best you could do is
run a 'cronjob' that periodically sets 'idle' logged in users as being logged
out.

not that the OP wanted to log the login and the logout of the user -
your code below doesn't cover that.

> 
> ------------------------8< snip >8---------------------------
> <?php
> require_once('classes/user.php'); // defines a class that needs to be
> de-serialized in the session.
> session_start(); //this must be called at the top of every page anyways.
> // user.php included above is needed so the session can instantiate the User
> object.
> 
> if ( !is_bool($_SESSION['login']) || $_SESSION['login'] != true ) //we
> specifically test 'true' here and boolean.
> { 
>       
> exit("<SCRIPT>location.href='/index.php?page=".base64_encode($_SERVER['REQUE
> ST_URI'])."';</SCRIPT>");
> } 
> else 
> {
>       SQL_DB ($_SESSION['companydb']); // Connect to their default
> V2_Database
>       SQL_QUERY("UPDATE ".$_SESSION['companydb'].".Users SET LastAccessed
> = NOW() WHERE CoreID = '".$_SESSION['coreid']."' LIMIT 1");
>       
>       if ((!isset($_COOKIE['sid']) && (time() - $_SESSION['last_access']
>> = $_SESSION['login_timeout'])) )
>       {
>               echo "<script>alert('Your session has been idle for >
> ".$_SESSION['login_timeout']."
> seconds.');location.href='./index.php';</script>";
>               require_once("/your/path/htdocs/index.php");
>               exit;
>       }
>       
>       $_SESSION['last_access'] = time();
> }
> ?>
> 
> And in case you wonder why I store the base64 of the current page, it's so
> that after you authenticate them, you can gracefully pass them on to where
> they were trying to go (if they weren't logged in, or had timed out),
> complete with all $_GET parameters in tact...
> 
> if ($_REQUEST['page'])
>       header("Location: ".base64_decode($_REQUEST['page']));
> else
>       header("Location: some_other_page.php");
> 

--- End Message ---
--- Begin Message ---
Hi,

As i'm new to PEAR world, i try to understand how does it work.
for that i took the MDB2 and try to use it with PostgreSQL.

here is a basic sample extract from PEAR help file and only modified.

require_once 'Pear/MDB2.php';
$dsn = 'pgsql://login:[EMAIL PROTECTED]';

$mdb2 =& MDB2::connect($dsn);
if (PEAR::isError($mdb2))
{
die($mdb2->getMessage());
}

$res =& $mdb2->query('SELECT * FROM articles');
while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC))
{
echo $row['title'] . ', ' . $row['content'] . "\n";
}
$res->free();

when i try this code, the following error is raised :
Call to undefined method MDB2_Error::fetchRow() which points to ==> while
($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC))

So i'm lost now ?
i have the feeling that something is missing but what ?

thanks a lot,

Al.

--- End Message ---
--- Begin Message ---
Mark,

this is my main_includes.php file :

<?php
   $path = 'pear';
   set_include_path(get_include_path() . PATH_SEPARATOR . $path);

   require_once "Structures/DataGrid.php";
   require_once 'MDB2.php';
?>

and in my file where i try to use MDB2.php, it's included like that :

<?php
   include_once('includes/main_include.php');
?>
at the beginning of my file before all META

Articles table exists in my database, i've checked also if i did not make
some mistakes in the user name, password or dbnane in my dsn,
but as i do not have any error raised from the database connection. I guess
that everything is correct.

Al.

On 11/11/06, Mark Wiesemann <[EMAIL PROTECTED]> wrote:

Alain Roger wrote:
> I have a main_includes.php which include_once/require_once all needed
> things like
> MDB2.php or setpath for /pear folder

Okay, but remember that the PEAR dir needs to in the include_path.
Otherwise, e.g. MDB2 won't find its own files and might not work as
expected.

> Anyway, you are right.
> issue is on the Query command.
> Here is the error message :
> MDB2 Error: unknown error
> _doQuery: [Error message: Could not execute statement] [Last executed
> query: SELECT * FROM articles]
> but it does not help me so much this error.

Is this the output of getMessage() and getDebugInfo(). If it isn't,
getDebugInfo() should give you more information.

Anyway: Does the articles table exist in your database?

Regards,
Mark


--- End Message ---
--- Begin Message ---
---------- Forwarded message ----------
From: Alain Roger <[EMAIL PROTECTED]>
Date: Nov 11, 2006 12:26 PM
Subject: Re: MDB2 simple test
To: Mark Wiesemann <[EMAIL PROTECTED]>

I have a main_includes.php which include_once/require_once all needed things
like
MDB2.php or setpath for /pear folder

Anyway, you are right.
issue is on the Query command.
Here is the error message :
MDB2 Error: unknown error
_doQuery: [Error message: Could not execute statement] [Last executed query:
SELECT * FROM articles]
but it does not help me so much this error.

Ok, it can not execute the query but why ?
example if from the PEAR help file :-(

Al.


On 11/11/06, Mark Wiesemann <[EMAIL PROTECTED]> wrote:

[FYI: This is a copy of a message posted to <news:php.pear.general>
Message-ID: <[EMAIL PROTECTED]>]

Alain Roger wrote:
> As i'm new to PEAR world, i try to understand how does it work.
> for that i took the MDB2 and try to use it with PostgreSQL.
>
> here is a basic sample extract from PEAR help file and only modified.
>
> require_once 'Pear/MDB2.php';

This line should be better:
require_once 'MDB2.php';
(and the PEAR directory should be in your include_path)

> $dsn = 'pgsql://login:[EMAIL PROTECTED]';
>
> $mdb2 =& MDB2::connect($dsn);
> if (PEAR::isError($mdb2))
> {
>  die($mdb2->getMessage());
> }
>
> $res =& $mdb2->query('SELECT * FROM articles');

You need to an error check here:
if (PEAR::isError($res)) {
  die($res->getMessage() . '<br />' . $res->getDebugInfo());
}

It's very likely that the following error about fetchRow() is caused
because the query failed: fetchRow() would then be called on an
MDB2_Error (or PEAR_Error) object which, of course, does not have a
fetchRow() method.

> while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC))
> {
>  echo $row['title'] . ', ' . $row['content'] . "\n";
> }
> $res->free();
>
> when i try this code, the following error is raised :
> Call to undefined method MDB2_Error::fetchRow() which points to ==>
while
> ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC))

Regards,
Mark


--- End Message ---
--- Begin Message ---
for more information, here is the variable where points the include_path :

include path = F:\My documents\Development\Website\Immense\Pear

as i did not install PEAR via script, i uncompress it and copy files into
Pear folder.
i did this because my web hoster will not accept to install PEAR on his
server.
in folder : F:\My documents\Development\Website\Immense\Pear, i have all
standard PEAR folder installation files... e.g. PEAR.PHP, MDB2.PHP, and
relative subfolders.

Al.

On 11/11/06, Alain Roger <[EMAIL PROTECTED]> wrote:

Mark,

this is my main_includes.php file :

<?php
    $path = 'pear';
    set_include_path(get_include_path() . PATH_SEPARATOR . $path);

    require_once "Structures/DataGrid.php";
    require_once 'MDB2.php';
?>

and in my file where i try to use MDB2.php, it's included like that :

<?php
    include_once('includes/main_include.php');
?>
at the beginning of my file before all META

Articles table exists in my database, i've checked also if i did not make
some mistakes in the user name, password or dbnane in my dsn,
but as i do not have any error raised from the database connection. I
guess that everything is correct.

Al.

On 11/11/06, Mark Wiesemann <[EMAIL PROTECTED]> wrote:
>
> Alain Roger wrote:
> > I have a main_includes.php which include_once/require_once all needed
> > things like
> > MDB2.php or setpath for /pear folder
>
> Okay, but remember that the PEAR dir needs to in the include_path.
> Otherwise, e.g. MDB2 won't find its own files and might not work as
> expected.
>
> > Anyway, you are right.
> > issue is on the Query command.
> > Here is the error message :
> > MDB2 Error: unknown error
> > _doQuery: [Error message: Could not execute statement] [Last executed
> > query: SELECT * FROM articles]
> > but it does not help me so much this error.
>
> Is this the output of getMessage() and getDebugInfo(). If it isn't,
> getDebugInfo() should give you more information.
>
> Anyway: Does the articles table exist in your database?
>
> Regards,
> Mark
>



--- End Message ---
--- Begin Message ---
Hi,

I'm still working on the issue with MDB2.

i've checked the $mdb2 object and i discover that method doQuery does not
exist when i write $mdb2->
So it seems that MDB2.php does not pickup the datasource package pgsql.php.

Therefore i would like to know if the following folder struture is correct :

- Pear
|
|-MDB2.php
|-..
|-\MDB2\
            |-\Driver
                      |-pgsql.php
                      |-  --> each subfolder has : pgsql.php and
common.phpfiles
            |-...

here is my code in my php file :
$dsn = 'pgsql://my_login:[EMAIL PROTECTED]';
$mdb2 =& MDB2::connect($dsn);
if (PEAR::isError($mdb2))
{
die($mdb2->getMessage());
}

$res =& $mdb2->query('SELECT * FROM articles');
if (PEAR::isError($res))
{
die($res->getMessage() . '<br />' . $res->getDebugInfo());
}


thanks a lot,
Alain

--- End Message ---

Reply via email to