buy propranolol online generic, citrusandcandy.com, citrus & candy, dynamicbusiness.com.au, purchase premarin online, no prescription needed amoxil, dynamicbusiness.com.au

Categories

PHP MySQli functions quick reference

mysqli_affected_rows()  Returns the number of affected rows in the previous MySQL operation
mysqli_autocommit()  Turns on or off auto-committing database modifications
mysqli_change_user()  Changes the user of the specified database connection
mysqli_character_set_name()  Returns the default character set for the database connection
mysqli_close()  Closes a previously opened database connection
mysqli_commit()  Commits the current transaction
mysqli_connect_errno()  Returns the error code from the last connection error
mysqli_connect_error()  Returns the error description from the last connection error
mysqli_connect()  Opens a new connection to the MySQL server
mysqli_data_seek()  Adjusts the result pointer to an arbitrary row in the result-set
mysqli_debug()  Performs debugging operations
mysqli_dump_debug_info()  Dumps debugging info into the log
mysqli_errno()  Returns the last error code for the most recent function call
mysqli_error_list()  Returns a list of errors for the most recent function call
mysqli_error()  Returns the last error description for the most recent function call
mysqli_fetch_all()  Fetches all result rows as an associative array, a numeric array, or both
mysqli_fetch_array()  Fetches a result row as an associative, a numeric array, or both
mysqli_fetch_assoc()  Fetches a result row as an associative array
mysqli_fetch_field_direct()  Returns meta-data for a single field in the result set, as an object
mysqli_fetch_field()  Returns the next field in the result set, as an object
mysqli_fetch_fields()  Returns an array of objects that represent the fields in a result set
mysqli_fetch_lengths()  Returns the lengths of the columns of the current row in the result set
mysqli_fetch_object()  Returns the current row of a result set, as an object
mysqli_fetch_row()  Fetches one row from a result-set and returns it as an enumerated array
mysqli_field_count()  Returns the number of columns for the most recent query
mysqli_field_seek()  Sets the field cursor to the given field offset
mysqli_field_tell()  Returns the position of the field cursor
mysqli_free_result()  Frees the memory associated with a result
mysqli_get_charset()  Returns a character set object
mysqli_get_client_info()  Returns the MySQL client library version
mysqli_get_client_stats()  Returns statistics about client per-process
mysqli_get_client_version()  Returns the MySQL client library version as an integer
mysqli_get_connection_stats()  Returns statistics about the client connection
mysqli_get_host_info()  Returns the MySQL server hostname and the connection type
mysqli_get_proto_info()  Returns the MySQL protocol version
mysqli_get_server_info()  Returns the MySQL server version
mysqli_get_server_version()  Returns the MySQL server version as an integer
mysqli_info()  Returns information about the most recently executed query
mysqli_init()  Initializes MySQLi and returns a resource for use with mysqli_real_connect()
mysqli_insert_id()  Returns the auto-generated id used in the last query
mysqli_kill()  Asks the server to kill a MySQL thread
mysqli_more_results()  Checks if there are more results from a multi query
mysqli_multi_query()  Performs one or more queries on the database
mysqli_next_result()  Prepares the next result set from mysqli_multi_query()
mysqli_num_fields()  Returns the number of fields in a result set
mysqli_num_rows()  Returns the number of rows in a result set
mysqli_options()  Sets extra connect options and affect behavior for a connection
mysqli_ping()  Pings a server connection, or tries to reconnect if the connection has gone down
mysqli_prepare()  Prepares an SQL statement for execution
mysqli_query()  Performs a query against the database
mysqli_real_connect()  Opens a new connection to the MySQL server
mysqli_real_escape_string()  Escapes special characters in a string for use in an SQL statement
mysqli_real_query()  Executes an SQL query
mysqli_reap_async_query()  Returns the result from async query
mysqli_refresh()  Refreshes tables or caches, or resets the replication server information
mysqli_rollback()  Rolls back the current transaction for the database
mysqli_select_db()  Changes the default database for the connection
mysqli_set_charset()  Sets the default client character set
mysqli_set_local_infile_default()  Unsets user defined handler for load local infile command
mysqli_set_local_infile_handler()  Set callback function for LOAD DATA LOCAL INFILE command
mysqli_sqlstate()  Returns the SQLSTATE error code for the last MySQL operation
mysqli_ssl_set()  Used to establish secure connections using SSL
mysqli_stat()  Returns the current system status
mysqli_stmt_init()  Initializes a statement and returns an object for use with mysqli_stmt_prepare()
mysqli_store_result()  Transfers a result set from the last query
mysqli_thread_id()  Returns the thread ID for the current connection
mysqli_thread_safe()  Returns whether the client library is compiled as thread-safe
mysqli_use_result()  Initiates the retrieval of a result set from the last query executed using the mysqli_real_query()
mysqli_warning_count()  Returns the number of warnings from the last query in the connection
FacebookTwitterGoogle+PinterestTumblrStumbleUponRedditLinkedInWhatsAppBaiduBlinklistDeliciousDiggDiigoOdnoklassnikiPlurkWordPressBlogger PostEmailShare

Remove a directory and contents

Remove a directory and contents , use with care

function rmdir_recursive($dir){
  $files = scandir($dir);
  foreach ($files as $file) {
    if ($file == '.' OR $file == '..') continue;
    $file = "$dir/$file";
    if (is_dir($file)) {
      rmdir_recursive($file);
      rmdir($file);
    } else {
      unlink($file);
    }
  }
  rmdir($dir);
}
FacebookTwitterGoogle+PinterestTumblrStumbleUponRedditLinkedInWhatsAppBaiduBlinklistDeliciousDiggDiigoOdnoklassnikiPlurkWordPressBlogger PostEmailShare

Image resize function example

This was a user submission a while back, lost the details but its a nice, useful function

function resizeImage( $file, $thumbpath, $max_side = NULL , $fixfor = NULL, $cropped = false ) {
 
			// 1 = GIF, 2 = JPEG, 3 = PNG
 
		if ( file_exists( $file ) ) {
			$type = getimagesize( $file );
 
			if (!function_exists( 'imagegif' ) && $type[2] == 1 ) {
				$error = __( 'Filetype not supported. Thumbnail not created.' );
			}
			elseif (!function_exists( 'imagejpeg' ) && $type[2] == 2 ) {
				$error = __( 'Filetype not supported. Thumbnail not created.' );
			}
			elseif (!function_exists( 'imagepng' ) && $type[2] == 3 ) {
				$error = __( 'Filetype not supported. Thumbnail not created.' );
			} else {
 
				// create the initial copy from the original file
				if ( $type[2] == 1 ) {
					$image = imagecreatefromgif( $file );
				}
				elseif ( $type[2] == 2 ) {
					$image = imagecreatefromjpeg( $file );
				}
				elseif ( $type[2] == 3 ) {
					$image = imagecreatefrompng( $file );
				}
 
				if ( function_exists( 'imageantialias' ))
					imageantialias( $image, TRUE );
 
				$image_attr = getimagesize( $file );
				$max_side = $max_side ? $max_side : $image_attr[0]; 
				// figure out the longest side
			if($fixfor){
					if($fixfor == 'width'){
						$image_width = $image_attr[0];
					$image_height = $image_attr[1];
					$image_new_width = $max_side;
 
					$image_ratio = $image_width / $image_new_width;
					$image_new_height = $image_height / $image_ratio;
					}elseif($fixfor == 'height'){
					 $image_width = $image_attr[0];
					$image_height = $image_attr[1];
					$image_new_height = $max_side;
 
					$image_ratio = $image_height / $image_new_height;
					$image_new_width = $image_width / $image_ratio;	
					}
			}elseif($cropped){
			  $image_new_width = $max_side*2;
			  $image_ratio = $image_attr[0] / $image_new_width;
			  $image_new_height = $image_attr[1] / $image_ratio;
 
			  $image_resized_crop = imagecreatetruecolor( $image_new_width, $image_new_height);
			  @imagecopyresampled( $image_resized_crop, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1] );
 
			  $cropX = intval((imagesx($image_resized_crop) - $max_side) / 2);
			  $cropY = intval((imagesy($image_resized_crop) - $max_side) / 2);
 
			}else{
				if ( $image_attr[0] > $image_attr[1] ) {
					$image_width = $image_attr[0];
					$image_height = $image_attr[1];
					$image_new_width = $max_side;
 
					$image_ratio = $image_width / $image_new_width;
					$image_new_height = $image_height / $image_ratio;
					//width is > height
				} else {
					$image_width = $image_attr[0];
					$image_height = $image_attr[1];
					$image_new_height = $max_side;
 
					$image_ratio = $image_height / $image_new_height;
					$image_new_width = $image_width / $image_ratio;
					//height > width
				}
			}	
 
 
				if(!$cropped){
					$thumbnail = imagecreatetruecolor( $image_new_width, $image_new_height);
					@imagecopyresampled( $thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1] );
				}elseif($cropped){
					$thumbnail = imagecreatetruecolor( $max_side, $max_side);
					@imagecopyresampled( $thumbnail, $image_resized_crop, 0, 0, $cropX, $cropY, $max_side, $max_side, $max_side, $max_side);				
				}
 
				if (!imagejpeg( $thumbnail, $thumbpath ) ) {
						$error = 0;
					}
			}
		} else {
			$error = 0;
		}
 
		if (!empty ( $error ) ) {
			return $error;
		} else {
			return $thumbpath;
		}
	}
FacebookTwitterGoogle+PinterestTumblrStumbleUponRedditLinkedInWhatsAppBaiduBlinklistDeliciousDiggDiigoOdnoklassnikiPlurkWordPressBlogger PostEmailShare

Shorten a string function

A simple function to shorten a string

function shortenstring($txt,$size){
 
$short = $size - 3;
if(strlen($txt) > $size){
$data = substr( $txt, 0, $short )."...";
}
else
{
$data = $txt;
}
 
return $data;
}
 
 
echo shortenstring('The string to be shortened',15);

 

FacebookTwitterGoogle+PinterestTumblrStumbleUponRedditLinkedInWhatsAppBaiduBlinklistDeliciousDiggDiigoOdnoklassnikiPlurkWordPressBlogger PostEmailShare

Array examples

Example #1 A simple array

<?php
$array = array( "foo" => "bar", "bar" => "foo",);
// as of PHP 5.4$
array = [ "foo" => "bar", "bar" => "foo",];
?>

Example #2 Type Casting and Overwriting example

<?php
$array = array( 1 => "a", "1" => "b", 1.5 => "c", true => "d",);
var_dump($array);
?>

The above example will output:

array(1) {
[1]=>
string(1) “d”
}

As all the keys in the above example are cast to 1, the value will be overwritten on every new element and the last assigned value “d” is the only one left over.

Example #3 Mixed integer and string keys

<?php
$array = array( "foo" => "bar", "bar" => "foo", 100 => -100, -100 => 100,);
var_dump($array);
?>

The above example will output:

array(4) {
[“foo”]=>string(3) “bar”
[“bar”]=>string(3) “foo”
[100]=>int(-100)
[-100]=>int(100)
}

Example #4 Indexed arrays without key

<?php
$array = array("foo", "bar", "hello", "world");
var_dump($array);
?>

The above example will output:

array(4) {
[0]=>
string(3) “foo”
[1]=>
string(3) “bar”
[2]=>
string(5) “hello”
[3]=>
string(5) “world”
}

Example #5 Keys not on all elements

<?php
$array = array( "a", "b", 6 => "c", "d",);
var_dump($array);
?>

The above example will output:

array(4) {
[0]=>
string(1) “a”
[1]=>
string(1) “b”
[6]=>
string(1) “c”
[7]=>
string(1) “d”
}

As you can see the last value “d” was assigned the key 7. This is because the largest integer key before that was 6.

Example #6 Accessing array elements

<?php
$array = array( "foo" => "bar", 42 => 24, "multi" => array( "dimensional" => array( "array" => "foo" ) ));
var_dump($array["foo"]);
var_dump($array[42]);
var_dump($array["multi"]["dimensional"]["array"]);
?>

The above example will output:

string(3) “bar”
int(24)
string(3) “foo”
Example #7 Array dereferencing

<?php
function getArray() 
{ 
return array(1, 2, 3);
}
// on PHP 5.4
$secondElement = getArray()[1];
// previously$tmp = getArray();
$secondElement = $tmp[1];
// orlist(, $secondElement) = getArray();
?>

Example #8 Using array()

<?php
// Array as (property-)map$map = array( 'version' => 4, 'OS' => 'Linux', 'lang' => 'english', 'short_tags' => true );
// strictly numerical keys$array = array( 7, 8, 0, 156, -10 );
// this is the same as array(0 => 7, 1 => 8, ...)$switching = array( 10, // key = 0 5 => 6, 3 => 7, 'a' => 4, 11, // key = 6 (maximum of integer-indices was 5) '8' => 2, // key = 8 (integer!) '02' => 77, // key = '02' 0 => 12 // the value 10 will be overwritten by 12 ); 
// empty array$empty = array(); 
?>

Example #9 Collection

<?php
$colors = array('red', 'blue', 'green', 'yellow');
foreach ($colors as $color) 
{ 
echo "Do you like $color?\n";
}
?>

The above example will output:

Do you like red?
Do you like blue?
Do you like green?
Do you like yellow?

Example #10 Changing element in the loop

<?php
// PHP 5
foreach ($colors as &$color) 
{ 
$color = strtoupper($color);}unset($color); 
// ensure that following writes to$color will not modify the last array element 
// Workaround for older versions
foreach ($colors as $key => $color) 
{ 
$colors[$key] = strtoupper($color);
}
print_r($colors);
?>

The above example will output:

Array
(
[0] => RED
[1] => BLUE
[2] => GREEN
[3] => YELLOW
)

Example #11 One-based index

<?php
$firstquarter = array(1 => 'January', 'February', 'March');
print_r($firstquarter);
?>

The above example will output:

Array
(
[1] => ‘January’
[2] => ‘February’
[3] => ‘March’
)
Example #12 Filling an array

<?php
// fill an array with all items from a directory
$handle = opendir('.');
while (false !== ($file = readdir($handle))) 
{ 
$files[] = $file;
}
closedir($handle); 
?>

Example #13 Sorting an array

<?php
sort($files);
print_r($files);
?>

Example #14 Recursive and multi-dimensional arrays

<?php
$fruits = array ( "fruits" => array ( "a" => "orange", "b" => "banana", "c" => "apple" ), "numbers" => array ( 1, 2, 3, 4, 5, 6 ), "holes" => array ( "first", 5 => "second", "third" ) );
// Some examples to address values in the array above echo $fruits["holes"][5]; 
// prints "second"echo $fruits["fruits"]["a"]; 
// prints "orange"unset($fruits["holes"][0]); 
// remove "first"
// Create a new multi-dimensional array
$juices["apple"]["green"] = "good"; 
?>
FacebookTwitterGoogle+PinterestTumblrStumbleUponRedditLinkedInWhatsAppBaiduBlinklistDeliciousDiggDiigoOdnoklassnikiPlurkWordPressBlogger PostEmailShare