session_egister a 'resource' problem
| From: | Kees van den Broek | Date: | Wed, 09 Aug 2000 18:12:49 +0000 |
| Subject: | session_egister a 'resource' problem | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-10971@lists.php.net to get a copy of this message | ||
The problem:
Session_register("linkid"); won't work with resource type
Script1 opens a database connection and outputs 'Resource id #2'.
In a book i read (which was also updated for php4) this was the syntax for
odbc_pconnect:
int odbc_pconnect(string DSN, string user, string password [, int
cursor_option]
So I expected $linkid to be integer. After using the gettype command for
finding out what it REALLY was,
$linkid turned out to be of the 'resource' type.
To ensure i made no programming errors, i also made a $test (=string).
Script2 should query the database opened in script1. Therefore I need
$linkid (or should I say resource id).
$test is correctly registered because script2 outputs 'this is a test'. But
$linkid is empty.
I read that session_register only works with integers and strings, not with
objects or arrays (an probably
resources also). So what can I do to make it work.
I tried converting $linkid to integer (which leaves $linkid as integer with
value '2'), but odbc_exec doesn't
work with an int.
I can't find any documentation of this 'resource' type, and how to make it a
global.
Any help appreciated!
Kees
-------------
My configuration:
Windows 95
PHP 4.0.1pl2-win32
MySQL 3.23.19-beta-win
MyOBDC 2.50.31-win95
Apache 1.3.12-win32
The sources:
-------------
<?php
// script1
$linkid = odbc_pconnect ("mysql","sqladmin","sqladmin");
print $linkid;
$test="this is a test";
session_register("test");
session_register("linkid");
?>
<a href="script2.php?<?=sid?>">next</a>
-------------
<?php
// script2
print $test;
print $linkid;
$query="some query";
odbc_exec($linkid, $query);
session_destroy();
?>
-------------