TomTom 0 Posted August 3, 2012 Report Share Posted August 3, 2012 I am running PHP under XAMPP on a Windows 7 machine. When running Script 3.1 (saving session data to database), I received an error on line 53. When I changed the constant from 'MYSQLI_NUM' TO 'MYSQL_NUM' this corrected the error. Is this a typo or is there some other reason for this? Thanks very much. Quote Link to post Share on other sites
Jaepee 15 Posted August 3, 2012 Report Share Posted August 3, 2012 Post your source code ... Por Favor. Could you have mistakenly called mysql_connect instead of mysqli_connect? or _fetch_array or any other function? Quote Link to post Share on other sites
TomTom 0 Posted August 3, 2012 Author Report Share Posted August 3, 2012 Thanks so very much for replying... I hope I've included the code appropriately. I believe I've used "mysqli" exclusively in all my calls. Question (since I'm a newbie) - should I assume it to be MYSQLI_NUM for mysqli calls and MYSQL_NUM for the (older?) mysql calls? <?php # Script 3.1 - db_sessions.inc.php $sdbc = NULL; function open_session() { global $sdbc; $sdbc = mysqli_connect ('localhost', 'ts_ajax', 'jANuary18', 'ts_ajax') or die('Cannot connect to the database.'); return true; } function close_session() { global $sdbc; return mysqli_close($sdbc); } function read_session($sid) { global $sdbc; $q = sprintf('SELECT data FROM sessions WHERE id="%s"', mysqli_real_escape_string($sdbc,$sid)); $r = mysqli_query($sdbc,$q); if(mysqli_num_rows($r)==1) { list($data) = mysqli_fetch_array($r, MYSQL_NUM); return($data); } else { return '';} } function write_session($sid, $data) { global $sdbc; $q = sprintf('REPLACE INTO sessions (id, data) VALUES ("%s", "%s")', mysqli_real_escape_string($sdbc, $sid), mysqli_real_escape_string($sdbc, $data)); $r = mysqli_query($sdbc,$q); return mysqli_affected_rows($sdbc); } function destroy_session($sid) { global $sdbc; $q = sprintf('DELETE FROM sessions WHERE id="%s"', mysqli_real_escape_string($sdbc,$sid)); $r = mysqli_query($sdbc,$q); $_SESSION = array(); return mysqli_affected_rows($sdbc); } function clean_session($expire) { global $sdbc; $q = sprintf('DELETE FROM sessions WHERE DATE_ADD(last_accessed, INTERVAL %d SECOND) < NOW()', (int) $expire); $r = mysqli_query($sdbc,$q); return mysqli_affected_rows($sdbc); } session_set_save_handler('open_session', 'close_session', 'read_session', 'write_session', 'destroy_session', 'clean_session'); session_start(); ?> Quote Link to post Share on other sites
Larry 428 Posted August 3, 2012 Report Share Posted August 3, 2012 If you're using MySQL Improved extensions, you should use MYSQLI_NUM. I think you can get away with using MYSQL_NUM, however. 1 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.