PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Jenk
DevNet Master
Posts: 3587 Joined: Mon Sep 19, 2005 6:24 am
Location: London
Post
by Jenk » Mon Jul 31, 2006 2:20 pm
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
Last edited by
Jenk on Wed Aug 02, 2006 8:15 am, edited 1 time in total.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Jul 31, 2006 3:21 pm
Jenk
DevNet Master
Posts: 3587 Joined: Mon Sep 19, 2005 6:24 am
Location: London
Post
by Jenk » Mon Jul 31, 2006 4:01 pm
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)
Ollie Saunders
DevNet Master
Posts: 3179 Joined: Tue May 24, 2005 6:01 pm
Location: UK
Post
by Ollie Saunders » Mon Jul 31, 2006 4:18 pm
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.
Jenk
DevNet Master
Posts: 3587 Joined: Mon Sep 19, 2005 6:24 am
Location: London
Post
by Jenk » Mon Jul 31, 2006 4:30 pm
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);
}
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Mon Jul 31, 2006 4:37 pm
Except list($data)=... it works fine for me.
Jenk
DevNet Master
Posts: 3587 Joined: Mon Sep 19, 2005 6:24 am
Location: London
Post
by Jenk » Mon Jul 31, 2006 4:50 pm
wrong thread?
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Mon Jul 31, 2006 5:24 pm
No, I took the two scripts from
viewtopic.php?t=52676 and they work fine.
Jenk
DevNet Master
Posts: 3587 Joined: Mon Sep 19, 2005 6:24 am
Location: London
Post
by Jenk » Mon Jul 31, 2006 5:26 pm
oh right, yes they do 'work.'
I wanted to see if I could clear the warning errors.
Thank you for testing
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Mon Jul 31, 2006 5:28 pm
Ok, let me rephrase that.
Both scripts work - as in 'work without any error or warning'
Jenk
DevNet Master
Posts: 3587 Joined: Mon Sep 19, 2005 6:24 am
Location: London
Post
by Jenk » Mon Jul 31, 2006 5:44 pm
They don't here :/
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Mon Jul 31, 2006 5:58 pm
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);
}
}
?>
Jenk
DevNet Master
Posts: 3587 Joined: Mon Sep 19, 2005 6:24 am
Location: London
Post
by Jenk » Mon Jul 31, 2006 6:59 pm
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.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Tue Aug 01, 2006 5:23 am
And what about the error_logs?
Jenk
DevNet Master
Posts: 3587 Joined: Mon Sep 19, 2005 6:24 am
Location: London
Post
by Jenk » Tue Aug 01, 2006 5:26 am
the same.