Praful Kumar Web page - PHP Function 03


173. mysql_ping (PHP 4 >= 4.3.0, PHP 5, PECL mysql:1.0)
mysql_ping — Ping a server connection or reconnect if there is no connection
Description
bool mysql_ping ( [resource $link_identifier] )
Checks whether or not the connection to the server is working. If it has gone down, an automatic reconnection is attempted. This function can be used by scripts that remain idle for a long while, to check whether or not the server has closed the connection and reconnect if necessary.
Note: Since MySQL 5.0.13, automatic reconnection feature is disabled.




174. mysql_query (PHP 4, PHP 5, PECL mysql:1.0)
mysql_query — Send a MySQL query
Description
resource mysql_query ( string $query [, resource $link_identifier] )
mysql_query() sends an unique query (multiple queries are not supported) to the currently active database on the server that's associated with the specified link_identifier.




175. mysql_result (PHP 4, PHP 5, PECL mysql:1.0)
mysql_result — Get result data
Description
string mysql_result ( resource $result, int $row [, mixed $field] )
Retrieves the contents of one cell from a MySQL result set.
When working on large result sets, you should consider using one of the functions that fetch an entire row (specified below). As these functions return the contents of multiple cells in one function call, they're MUCH quicker than mysql_result(). Also, note that specifying a numeric offset for the field argument is much quicker than specifying a fieldname or tablename.fieldname argument.




176. mysql_select_db (PHP 4, PHP 5, PECL mysql:1.0)
mysql_select_db — Select a MySQL database
Description
bool mysql_select_db ( string $database_name [, resource $link_identifier] )
Sets the current active database on the server that's associated with the specified link identifier. Every subsequent call to mysql_query() will be made on the active database.




177. mysql_stat (PHP 4 >= 4.3.0, PHP 5, PECL mysql:1.0)
mysql_stat — Get current system status
Description
string mysql_stat ( [resource $link_identifier] )
mysql_stat() returns the current server status.




178. mysql_thread_id (PHP 4 >= 4.3.0, PHP 5, PECL mysql:1.0)
mysql_thread_id — Return the current thread ID
Description
int mysql_thread_id ( [resource $link_identifier] )
Retrieves the current thread ID. If the connection is lost, and a reconnect with mysql_ping() is executed, the thread ID will change. This means only retrieve the thread ID when needed.




179. mysql_unbuffered_query (PHP 4 >= 4.0.6, PHP 5, PECL mysql:1.0)
mysql_unbuffered_query — Send an SQL query to MySQL, without fetching and buffering the result rows
Description
resource mysql_unbuffered_query ( string $query [, resource $link_identifier] )
mysql_unbuffered_query() sends a SQL query query to MySQL, without fetching and buffering the result rows automatically, as mysql_query() does. On the one hand, this saves a considerable amount of memory with SQL queries that produce large result sets. On the other hand, you can start working on the result set immediately after the first row has been retrieved: you don't have to wait until the complete SQL query has been performed. When using multiple DB-connects, you have to specify the optional parameter link_identifier.




180. mysqli_affected_rows, (PHP 5)
mysqli_affected_rows, mysqli->affected_rows — Gets the number of affected rows in a previous MySQL operation
Description
Procedural style:
int mysqli_affected_rows ( mysqli $link )
Object oriented style (property):
Class mysqli {
int affected_rows
}
Returns the number of rows affected by the last INSERT, UPDATE, REPLACE or DELETE query.
For SELECT statements mysqli_affected_rows() works like mysqli_num_rows().




181. mysql_db_name (PHP 4, PHP 5, PECL mysql:1.0)
mysql_db_name — Get result data
Description
string mysql_db_name ( resource $result, int $row [, mixed $field] )
Retrieve the database name from a call to mysql_list_dbs().




182. move_uploaded_file (PHP 4 >= 4.0.3, PHP 5)
move_uploaded_file — Moves an uploaded file to a new location
Description
bool move_uploaded_file ( string $filename, string $destination )
This function checks to ensure that the file designated by filename is a valid upload file (meaning that it was uploaded via PHP's HTTP POST upload mechanism). If the file is valid, it will be moved to the filename given by destination.
This sort of check is especially important if there is any chance that anything done with uploaded files could reveal their contents to the user, or even to other users on the same system.




183. session_destroy (PHP 4, PHP 5)
session_destroy — Destroys all data registered to a session
Description
bool session_destroy ( void )
session_destroy() destroys all of the data associated with the current session. It does not unset any of the global variables associated with the session, or unset the session cookie.
In order to kill the session altogether, like to log the user out, the session id must also be unset. If a cookie is used to propagate the session id (default behavior), then the session cookie must be deleted. setcookie() may be used for that.
// Initialize the session.
// If you are using session_name("something"), don't forget it now!
session_start();

// Unset all of the session variables.
$_SESSION = array();

// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if (isset($_COOKIE[session_name()])) {
setcookie(session_name(), '', time()-42000, '/');
}

// Finally, destroy the session.
session_destroy();




184. session_encode (PHP 4, PHP 5)
session_encode — Encodes the current session data as a string
Description
string session_encode ( void )
session_encode() returns a string with the contents of the current session encoded within.




185. session_get_cookie_params (PHP 4, PHP 5)
session_get_cookie_params — Get the session cookie parameters
Description
array session_get_cookie_params ( void )
Gets the session cookie parameters.
Return Values
Returns an array with the current session cookie information, the array contains the following items:
• "lifetime" - The lifetime of the cookie in seconds.
• "path" - The path where information is stored.
• "domain" - The domain of the cookie.
• "secure" - The cookie should only be sent over secure connections.
• "httponly" - The cookie can only be accessed through the HTTP protocol.




186. session_id (PHP 4, PHP 5)
session_id — Get and/or set the current session id
Description
string session_id ( [string $id] )
session_id() is used to get or set the session id for the current session.
The constant SID can also be used to retrieve the current name and session id as a string suitable for adding to URLs. See also Session handling.




187. session_is_registered (PHP 4, PHP 5)
session_is_registered — Find out whether a global variable is registered in a session
Description
bool session_is_registered ( string $name )
Finds out whether a global variable is registered in a session.




188. session_module_name (PHP 4, PHP 5)
session_module_name — Get and/or set the current session module
Description
string session_module_name ( [string $module] )
session_module_name() gets the name of the current session module.




189. session_name (PHP 4, PHP 5)
session_name — Get and/or set the current session name
Description
string session_name ( [string $name] )
session_name() returns the name of the current session.
The session name is reset to the default value stored in session.name at request startup time. Thus, you need to call session_name() for every request (and before session_start() or session_register() are called).




190. session_regenerate_id (PHP 4 >= 4.3.2, PHP 5)
session_regenerate_id — Update the current session id with a newly generated one
Description
bool session_regenerate_id ( [bool $delete_old_session] )
session_regenerate_id() will replace the current session id with a new one, and keep the current session information.




191. session_register (PHP 4, PHP 5)
session_register — Register one or more global variables with the current session
Description
bool session_register ( mixed $name [, mixed $...] )
session_register() accepts a variable number of arguments, any of which can be either a string holding the name of a variable or an array consisting of variable names or other arrays. For each name, session_register() registers the global variable with that name in the current session.
You can also create a session variable by simply setting the appropriate member of the $_SESSION or $HTTP_SESSION_VARS (PHP < 4.1.0) array.

// Use of session_register() is deprecated
$barney = "A big purple dinosaur.";
session_register("barney");

// Use of $_SESSION is preferred, as of PHP 4.1.0
$_SESSION["zim"] = "An invader from another planet.";

// The old way was to use $HTTP_SESSION_VARS
$HTTP_SESSION_VARS["spongebob"] = "He's got square pants.";




192. session_save_path (PHP 4, PHP 5)
session_save_path — Get and/or set the current session save path
Description
string session_save_path ( [string $path] )
session_save_path() returns the path of the current directory used to save session data.




193. session_set_cookie_params (PHP 4, PHP 5)
session_set_cookie_params — Set the session cookie parameters
Description
void session_set_cookie_params ( int $lifetime [, string $path [, string $domain [, bool $secure [, bool $httponly]]]] )
Set cookie parameters defined in the php.ini file. The effect of this function only lasts for the duration of the script. Thus, you need to call session_set_cookie_params() for every request and before session_start() is called.




194. session_set_save_handler (PHP 4, PHP 5)
session_set_save_handler — Sets user-level session storage functions
Description
bool session_set_save_handler ( callback $open, callback $close, callback $read, callback $write, callback $destroy, callback $gc )
session_set_save_handler() sets the user-level session storage functions which are used for storing and retrieving data associated with a session. This is most useful when a storage method other than those supplied by PHP sessions is preferred. i.e. Storing the session data in a local database.
The following example provides file based session storage similar to the PHP sessions default save handler files. This example could easily be extended to cover database storage using your favorite PHP supported database engine.
function open($save_path, $session_name)
{
global $sess_save_path;

$sess_save_path = $save_path;
return(true);
}
function close()
{
return(true);
}

function read($id)
{
global $sess_save_path;

$sess_file = "$sess_save_path/sess_$id";
return (string) @file_get_contents($sess_file);
}

function write($id, $sess_data)
{
global $sess_save_path;

$sess_file = "$sess_save_path/sess_$id";
if ($fp = @fopen($sess_file, "w")) {
$return = fwrite($fp, $sess_data);
fclose($fp);
return $return;
} else {
return(false);
}
}
function destroy($id)
{
global $sess_save_path;

$sess_file = "$sess_save_path/sess_$id";
return(@unlink($sess_file));
}
function gc($maxlifetime)
{
global $sess_save_path;

foreach (glob("$sess_save_path/sess_*") as $filename) {
if (filemtime($filename) + $maxlifetime < time()) {
@unlink($filename);
}
}
return true;
}
session_set_save_handler("open", "close", "read", "write", "destroy", "gc");
session_start();// proceed to use sessions normally




195. session_start (PHP 4, PHP 5)
session_start — Initialize session data
Description
bool session_start ( void )
session_start() creates a session or resumes the current one based on the current session id that's being passed via a request, such as GET, POST, or a cookie.
If you want to use a named session, you must call session_name() before calling session_start().
session_start() will register internal output handler for URL rewriting when trans-sid is enabled. If a user uses ob_gzhandler or like with ob_start(), the order of output handler is important for proper output. For example, user must register ob_gzhandler before session start.




196. session_unregister (PHP 4, PHP 5)
session_unregister — Unregister a global variable from the current session
Description
bool session_unregister ( string $name )
session_unregister() unregisters the global variable named name from the current session.




197. session_unset (PHP 4, PHP 5)
session_unset — Free all session variables
Description
void session_unset ( void )
The session_unset() function frees all session variables currently registered.




198. session_write_close (PHP 4 >= 4.0.4, PHP 5)
session_write_close — Write session data and end session
Description
void session_write_close ( void )
End the current session and store session data.
Session data is usually stored after your script terminated without the need to call session_write_close(), but as session data is locked to prevent concurrent writes only one script may operate on a session at any time. When using framesets together with sessions you will experience the frames loading one by one due to this locking. You can reduce the time needed to load all the frames by ending the session as soon as all changes to session variables are done.




199. settype (PHP 4, PHP 5)
settype — Set the type of a variable
Description
bool settype ( mixed &$var, string $type )
Set the type of variable var to type.
$foo = "5bar"; // string
$bar = true; // boolean
settype($foo, "integer"); // $foo is now 5 (integer)
settype($bar, "string"); // $bar is now "1" (string)




200. getdate (PHP 4, PHP 5)
getdate — Get date/time information
Description
array getdate ( [int $timestamp] )
Returns an associative array containing the date information of the timestamp, or the current local time if no timestamp is given.








201. split (PHP 4, PHP 5)
split — Split string into array by regular expression
Description
array split ( string $pattern, string $string [, int $limit] )
Splits a string into array by regular expression
// Delimiters may be slash, dot, or hyphen
$date = "04/30/1973";
list($month, $day, $year) = split('[/.-]', $date);
echo "Month: $month; Day: $day; Year: $year
n";




202. spliti (PHP 4 >= 4.0.1, PHP 5)
spliti — Split string into array by regular expression case insensitive
Description
array spliti ( string $pattern, string $string [, int $limit] )
Splits a string into array by regular expression.
This function is identical to split() except that this ignores case distinction when matching alphabetic characters.

$string = "aBBBaCCCADDDaEEEaGGGA";
$chunks = spliti ("a", $string, 5);
print_r($chunks);
Array ( [0] => [1] => BBB [2] => CCC [3] => DDD [4] => EEEaGGGA)




203. array_unique (PHP 4 >= 4.0.1, PHP 5)
array_unique — Removes duplicate values from an array
Description
array array_unique ( array $array )
array_unique() takes input array and returns a new array without duplicate values.
Note that keys are preserved. array_unique() sorts the values treated as string at first, then will keep the first key encountered for every value, and ignore all following keys. It does not mean that the key of the first related value from the unsorted array will be kept.
Note: Two elements are considered equal if and only if (string) $elem1 === (string) $elem2. In words: when the string representation is the same.
The first element will be used.
$input = array("a" => "green", "red", "b" => "green", "blue", "red");
$result = array_unique($input);
print_r($result);

The above example will output:
Array ( [a] => green [0] => red [1] => blue)




204. array_flip (PHP 4, PHP 5)
array_flip — Exchanges all keys with their associated values in an array
Description
array array_flip ( array $trans )
array_flip() returns an array in flip order, i.e. keys from trans become values and values from trans become keys.
Note that the values of trans need to be valid keys, i.e. they need to be either integer or string. A warning will be emitted if a value has the wrong type, and the key/value pair in question will not be flipped.
If a value has several occurrences, the latest key will be used as its values, and all others will be lost.
$trans = array("a" => 1, "b" => 1, "c" => 2);
$trans = array_flip($trans);
print_r($trans);

now $trans is:
Array([1] => b [2] => c)




205. array_intersect (PHP 4 >= 4.0.1, PHP 5)
array_intersect — Computes the intersection of arrays
Description
array array_intersect ( array $array1, array $array2 [, array $ ...] )
array_intersect() returns an array containing all the values of array1 that are present in all the arguments. Note that keys are preserved.
$array1 = array("a" => "green", "red", "blue");
$array2 = array("b" => "green", "yellow", "red");
$result = array_intersect($array1, $array2);
print_r($result); .

The above example will output:
Array( [a] => green [0] => red)




206. each (PHP 4, PHP 5)
each — Return the current key and value pair from an array and advance the array cursor
Description
array each ( array &$array )
Returns the current key and value pair from the array array and advances the array cursor. This pair is returned in a four-element array, with the keys 0, 1, key, and value. Elements 0 and key contain the key name of the array element, and 1 and value contain the data.
If the internal pointer for the array points past the end of the array contents, each() returns FALSE.
$foo = array("bob", "fred", "jussi", "jouni", "egon", "marliese");
$bar = each($foo);
print_r($bar);

$bar now contains the following key/value pairs:
Array( [1] => bob [value] => bob [0] => 0 [key] => 0)




208. error_log (PHP 4, PHP 5)
error_log — Send an error message somewhere
Description
bool error_log ( string $message [, int $message_type [, string $destination [, string $extra_headers]]] )
Sends an error message to the web server's error log, a TCP port or to a file.
// Send notification through the server log if we can not
// connect to the database.
if (!Ora_Logon($username, $password)) {
error_log("Oracle database not available!", 0);
}
// Notify administrator by email if we run out of FOO
if (!($foo = allocate_new_foo())) {
error_log("Big trouble, we're all out of FOOs!", 1,
"operator@example.com");
}
// other ways of calling error_log():
error_log("You messed up!", 2, "127.0.0.1:7000");
error_log("You messed up!", 2, "loghost");
error_log("You messed up!", 3, "/var/tmp/my-errors.log");




209. in_array (PHP 4, PHP 5)
in_array — Checks if a value exists in an array
Description
bool in_array ( mixed $needle, array $haystack [, bool $strict] )
Searches haystack for needle and returns TRUE if it is found in the array, FALSE otherwise.
If the third parameter strict is set to TRUE then the in_array() function will also check the types of the needle in the haystack.
Note: If needle is a string, the comparison is done in a case-sensitive manner.
Note: In PHP versions before 4.2.0 needle was not allowed to be an array.

$os = array("Mac", "NT", "Irix", "Linux");
if (in_array("Irix", $os)) {
echo "Got Irix";
}
if (in_array("mac", $os)) {
echo "Got mac";
}
The second condition fails because in_array() is case-sensitive, so the program above will display:
Got Irix




210. rmdir (PHP 4, PHP 5)
rmdir — Removes directory
Description
bool rmdir ( string $dirname [, resource $context] )
Attempts to remove the directory named by dirname. The directory must be empty, and the relevant permissions must permit this.




211. serialize (PHP 4, PHP 5, PECL axis2:0.1.0-0.1.1)
serialize — Generates a storable representation of a value
Description
string serialize ( mixed $value )
Generates a storable representation of a value
This is useful for storing or passing PHP values around without losing their type and structure.
To make the serialized string into a PHP value again, use unserialize().

$conn = odbc_connect("webdb", "php", "chicken");
$stmt = odbc_prepare($conn,
"UPDATE sessions SET data = ? WHERE id = ?");
$sqldata = array (serialize($session_data), $_SERVER['PHP_AUTH_USER']);
if (!odbc_execute($stmt, &$sqldata)) {
$stmt = odbc_prepare($conn,
"INSERT INTO sessions (id, data) VALUES(?, ?)");
if (!odbc_execute($stmt, &$sqldata)) {
/* Something went wrong.. */
}
}

Today, there have been 98881 visitors (297298 hits) on this page!
=> Do you also want a homepage for free? Then click here! <=