Datatypes in PHP - Resources : Tutorial



8. Resources datatype



Resource is a special variable in PHP which holds a reference to an external resource.

Resource variables can hold special handlers to opened files, database connections, image canvas areas e.t.c.

The resources are created and used by special functions,

List of some functions which create, use or destroy PHP resources



Resource stream (file handle) can be created from,
  fopen()
  tmpfile()
and used by,
  feof() 
  fflush()
  fgetc()
  fgetcsv()
  fgets()
  fgetss()
  flock()
  fpassthru()
  fputs()
  fwrite()
  fread()
  fseek()
  ftell()
  fstat()
  ftruncate()
  set_file_buffer()
  rewind()

and destroyed by fclose()

Resource msql query is created by,
  msql_db_query()
  msql_list_dbs()
  msql_list_fields()
  msql_list_tables()
  msql_query()
and used by,
  msql()
  msql_affected_rows()
  msql_data_seek()
  msql_dbname()
  msql_fetch_array()
  msql_fetch_field()
  msql_fetch_object()
  msql_fetch_row()
  msql_field_seek()
  msql_field_table()
  msql_field_flags()
  msql_field_len()
  msql_field_name()
  msql_field_type()
  msql_num_fields()
  msql_num_rows()
  msql_numfields()
  msql_numrows()
  msql_result()




Resource xml is created by functions xml_parser_create(), xml_parser_create_ns(), and used by,
  xml_set_object()
  xml_set_element_handler()
  xml_set_character_data_handler()
  xml_set_processing_instruction_handler()
  xml_set_default_handler()
  xml_set_unparsed_entity_decl_handler()
  xml_set_notation_decl_handler()
  xml_set_external_entity_ref_handler()
  xml_parse(), xml_get_error_code()
  xml_error_string()
  xml_get_current_line_number()
  xml_get_current_column_number()
  xml_get_current_byte_index()
  xml_parse_into_struct()
  xml_parser_set_option()
  xml_parser_get_option()




Resource aspell is created by aspell_new() and is used by,
  aspell_check()
  aspell_check_raw()
  aspell_suggest()



Resource bzip2 is created by bzopen() and is used by,
  bzerrno()
  bzerror()
  bzerrstr()
  bzflush()
  bzread()
  bzwrite()




The function is_resource() can be used to determine if a variable is a resource and function get_resource_type() will return the type of resource it is.