vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=187)
-   -   The joys of serializing data (https://vborg.vbsupport.ru/showthread.php?t=54465)

filburt1 06-17-2003 10:00 PM

The joys of serializing data
 
To serialize a variable or object in PHP means to take the variable or object and convert it to a string that can be stored anywhere, including, relevant to vB, a MySQL database. Later, it can be unserialized, at which point it'll be (nearly) exactly the same as when it was serialized.

An example:
PHP Code:

$serialized serialize($myobject);
.
.
.
$myobjectagain unserialize($serialized);
$myobjectagain->method(); 

Remember to addslashes $serialized when making a query because it could contain quotes. Also note that some tiny things can be lost when serializing; namely, internal array pointers, among others.

Reference:
http://www.php.net/serialize
http://www.php.net/unserialize (way faster than serializing)

MUG 06-18-2003 12:11 AM

Note that you can't serialize resources (such as a mysql connection) so the example posted won't work.

filburt1 06-18-2003 12:39 AM

The example itself should work, though, because $DB_site is just an object that never stores a result handle (at least not permanently).

MUG 06-18-2003 12:42 AM

Quote:

Today at 09:39 PM filburt1 said this in Post #3
The example itself should work, though, because $DB_site is just an object that never stores a result handle (at least not permanently).
One of the variables in $DB_site is $link_id and that can't be serialized. ;)
$query_id can't be serialized either.

In order to run $DB_site->query(), $link_id has to be a valid MySQL connection resource.

filburt1 06-18-2003 01:03 AM

Oh, good point ;)

But the concept is there ;)

Boofo 02-12-2004 07:33 AM

Great! A thread on serializing. ;)

I'm just starting to learn this. Maybe you can answer this question, filburt. How do we determine this when making the query for the datstore?

PHP Code:

"newusers";s:1:"0";s:14:"getthreadviews";s:1:"0";s:9

That's a snippet of caode we're using. What are the s:1 and the s:9 (and s:14) for? I know the zero is for the default value. And is there an easier way to list this so it can be added to easily?

Andreas 02-12-2004 08:41 AM

s(tring):(Length)1:(Value)"0";s(tring):(Length)14:(Value)"getthreadviews";

I'd guess.

Boofo 02-12-2004 09:49 AM

Why would you need 2 string lengths in there? ;)

Andreas 02-12-2004 09:59 AM

PHP Code:

s:1:"0";s:14:"getthreadviews" 

Arn't there two strings - "0" (length 1) and "getthreadviews" (length 14)?

Boofo 02-12-2004 10:40 AM

Ahhh, ok, now I understand. ;)

Thank you, sir. ;)


All times are GMT. The time now is 04:32 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01162 seconds
  • Memory Usage 1,736KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete