Page 1 of 2
static properties can contain resources? [resolved. at last]
Posted: Mon Jul 31, 2006 2:20 pm
by Jenk
hihi..
following from my embarrassing
session handler thread, I'm now getting errors reported ala below:
Warning: mysql_real_escape_string(): 7 is not a valid
MySQL-Link resource in E:\Program Files\Apache
Group\Apache2\htdocs\stkmart\includes\classes\jmt_Session.class.php on line 43
for all mysql_* funcs within the class (see link to other thread for code)
This leads me to belive static properties cannot contain resources? Even though it works, it still gives the errors?!
(nb: if I remove self::$link from all the mysql_* funcs, it ceases to function.)
Much obliged

Posted: Mon Jul 31, 2006 3:21 pm
by feyd
Posted: Mon Jul 31, 2006 4:01 pm
by Jenk
I've tried by ref as well, but it still generates the warning (and also generates the 'only variables should be assigned by reference' E_STRICT)
Posted: Mon Jul 31, 2006 4:18 pm
by Ollie Saunders
Sounds like the connection isn't being made to me.
Change this:
Code: Select all
public static function open ()
{
if (self::$link = mysql_connect(self::$db['HOST'], self::$db['USER'], self::$db['PASS'])) {
return mysql_select_db(self::$db['DATABASE'], self::$link);
} else {
return false;
}
}
To throw exceptions (pref.) or trigger_errors.
Posted: Mon Jul 31, 2006 4:30 pm
by Jenk
The connection is being made. Hence it having a resource id of 7 and not stating false.
I can also see this is true because the session is working, session data is being read/written in the DB and on screen, however I still get the warnings.
Code: Select all
public static function open ()
{
if (self::$link = mysql_connect(self::$db['HOST'], self::$db['USER'], self::$db['PASS'])) {
var_dump(self::$link);
return mysql_select_db(self::$db['DATABASE'], self::$link);
} else {
return false;
}
}
however..
Code: Select all
public static function close ()
{
var_dump(self::$link);
return mysql_close(self::$link);
}
Posted: Mon Jul 31, 2006 4:37 pm
by volka
Except list($data)=... it works fine for me.
Posted: Mon Jul 31, 2006 4:50 pm
by Jenk
wrong thread?
Posted: Mon Jul 31, 2006 5:24 pm
by volka
No, I took the two scripts from
viewtopic.php?t=52676 and they work fine.
Posted: Mon Jul 31, 2006 5:26 pm
by Jenk
oh right, yes they do 'work.'
I wanted to see if I could clear the warning errors.
Thank you for testing

Posted: Mon Jul 31, 2006 5:28 pm
by volka
Ok, let me rephrase that.
Both scripts work - as in 'work without any error or warning'

Posted: Mon Jul 31, 2006 5:44 pm
by Jenk
They don't here :/
Posted: Mon Jul 31, 2006 5:58 pm
by volka
line 43 is which one exactly?
Maybe some error_log entries will help to find the error
Code: Select all
<?php
class jmt_Session
{
private static $db = array();
private static $link;
public static function set(array $db)
{
self::$db = $db;
}
public static function open()
{
if (self::$link = mysql_connect(self::$db['HOST'], self::$db['USER'], self::$db['PASS'])) {
$retval = mysql_select_db(self::$db['DATABASE'], self::$link);
} else {
$retval = false;
}
error_log('jmt_Session::open '.(($retval)?'success':mysql_error()));
return $retval;
}
public static function close ()
{
return mysql_close(self::$link);
}
public static function read($id)
{
$id = mysql_real_escape_string($id, self::$link);
$sql = "SELECT `data` FROM `session` WHERE `sessionId` = '$id'";
error_log('jmt_Session::read '.$sql);
if ($result = mysql_query($sql, self::$link)) {
$row = mysql_fetch_assoc($result);
error_log('jmt_Session::read '.$row['data']);
return $row['data'];
} else {
error_log('jmt_Session::read no data');
return '';
}
}
public static function write($id, $data)
{
$access = time();
$id = mysql_real_escape_string($id, self::$link);
$data = mysql_real_escape_string($data, self::$link);
$sql = "REPLACE
INTO `session` (`sessionId`, `access`, `data`)
VALUES ('$id', '$access', '$data')";
error_log('jmt_Session::write '.$sql);
return mysql_query($sql, self::$link);
}
public static function destroy ($id)
{
$id = mysql_real_escape_string($id, self::$link);
$sql = "DELETE FROM `session` WHERE `sessionId` = '$id'";
return mysql_query($sql, self::$link);
}
public static function clean($max)
{
$old = time() - $max;
$sql = "DELETE
FROM `session`
WHERE `access` < '$old'";
return mysql_query($sql, self::$link);
}
}
?>
Posted: Mon Jul 31, 2006 6:59 pm
by Jenk
Code: Select all
public static function write($id, $data)
{
$access = time();
$id = mysql_real_escape_string($id, self::$link); //this line
however, that is only one of the messages. I receive a warning on every line that self::$link is used, except for where it is set.
Posted: Tue Aug 01, 2006 5:23 am
by volka
And what about the error_logs?
Posted: Tue Aug 01, 2006 5:26 am
by Jenk
the same.