Skip to main content

PHP in-built functions

PHP Basic Functions
 
Function Description
array() Creates an array
array_push() Inserts one or more elements to the end of an array
shuffle() Shuffles an array
sizeof() Alias of count()
sort() Sorts an array
count() Counts elements in an array, or properties in an object
uasort() Sorts an array with a user-defined function and maintain index association
date() Formats a local time/date
getdate() Returns an array that contains date and time information for a Unix timestamp
mktime() Returns the Unix timestamp for a date
strftime() Formats a local time/date according to locale settings
strptime() Parses a time/date generated with strftime()
time() Returns the current time as a Unix timestamp
chdir() Changes the current directory
dir() Opens a directory handle and returns an object
addcslashes() Returns a string with backslashes in front of the specified characters
addslashes() Returns a string with backslashes in front of predefined characters
echo() Outputs strings
explode() Breaks a string into an array
fprintf() Writes a formatted string to a specified output stream
htmlentities() Converts characters to HTML entities
htmlspecialchars_decode() Converts some predefined HTML entities to characters
htmlspecialchars() Converts some predefined characters to HTML entities
implode() Returns a string from the elements of an array
trim() Strips whitespace from the left side of a string
md5() Calculates the MD5 hash of a string
nl2br() Inserts HTML line breaks in front of each newline in a string
print() Outputs a string
printf() Outputs a formatted string
sprintf() Writes a formatted string to a variable
str_repeat() Repeats a string a specified number of times
str_replace() Replaces some characters in a string (case-sensitive)
str_shuffle() Randomly shuffles all characters in a string
str_split() Splits a string into an array
str_word_count() Count the number of words in a string
strchr() Finds the first occurrence of a string inside another string (alias of strstr())
strcmp() Compares two strings (case-sensitive)
strip_tags() Strips HTML and PHP tags from a string
stripcslashes() Unquotes a string quoted with addcslashes()
stripslashes() Unquotes a string quoted with addslashes()
stripos() Returns the position of the first occurrence of a string inside another string (case-insensitive)
strtolower() Converts a string to lowercase letters
strtoupper() Converts a string to uppercase letters
substr() Returns a part of a string
substr_compare() Compares two strings from a specified start position (binary safe and optionally case-sensitive)
substr_count() Counts the number of times a substring occurs in a string
substr_replace() Replaces a part of a string with another string
ucfirst() Converts the first character of a string to uppercase
ucwords() Converts the first character of each word in a string to uppercase
wordwrap() Wraps a string to a given number of characters
mail() Allows you to send emails directly from a script
 
PHP MySQL Functions
Function Description
mysql_affected_rows() Returns the number of affected rows in the previous MySQL operation
mysql_change_user() Deprecated. Changes the user of the current MySQL connection
mysql_client_encoding() Returns the name of the character set for the current connection
mysql_close() Closes a non-persistent MySQL connection
mysql_connect() Opens a non-persistent MySQL connection
mysql_create_db() Deprecated. Creates a new MySQL database. Use mysql_query() instead
mysql_data_seek() Moves the record pointer
mysql_db_name() Returns a database name from a call to mysql_list_dbs()
mysql_db_query() Deprecated. Sends a MySQL query. Use mysql_select_db() and mysql_query() instead
mysql_drop_db() Deprecated. Deletes a MySQL database. Use mysql_query() instead
mysql_errno() Returns the error number of the last MySQL operation
mysql_error() Returns the error description of the last MySQL operation
mysql_escape_string() Deprecated. Escapes a string for use in a mysql_query. Use mysql_real_escape_string() instead
mysql_fetch_array() Returns a row from a recordset as an associative array and/or a numeric array
mysql_fetch_assoc() Returns a row from a recordset as an associative array
mysql_fetch_field() Returns column info from a recordset as an object
mysql_fetch_lengths() Returns the length of the contents of each field in a result row
mysql_fetch_object() Returns a row from a recordset as an object
mysql_fetch_row() Returns a row from a recordset as a numeric array
mysql_field_flags() Returns the flags associated with a field in a recordset
mysql_field_len() Returns the maximum length of a field in a recordset
mysql_field_name() Returns the name of a field in a recordset
mysql_field_seek() Moves the result pointer to a specified field
mysql_field_table() Returns the name of the table the specified field is in
mysql_field_type() Returns the type of a field in a recordset
mysql_free_result() Free result memory
mysql_get_client_info() Returns MySQL client info
mysql_get_host_info() Returns MySQL host info
mysql_get_proto_info() Returns MySQL protocol info
mysql_get_server_info() Returns MySQL server info
mysql_info() Returns information about the last query
mysql_insert_id() Returns the AUTO_INCREMENT ID generated from the previous INSERT operation
mysql_list_dbs() Lists available databases on a MySQL server
mysql_list_fields() Deprecated. Lists MySQL table fields. Use mysql_query() instead
mysql_list_processes() Lists MySQL processes
mysql_list_tables() Deprecated. Lists tables in a MySQL database. Use mysql_query() instead
mysql_num_fields() Returns the number of fields in a recordset
mysql_num_rows() Returns the number of rows in a recordset
mysql_pconnect() Opens a persistent MySQL connection
mysql_ping() Pings a server connection or reconnects if there is no connection
mysql_query() Executes a query on a MySQL database
mysql_real_escape_string() Escapes a string for use in SQL statements
mysql_result() Returns the value of a field in a recordset
mysql_select_db() Sets the active MySQL database
mysql_stat() Returns the current system status of the MySQL server
mysql_tablename() Deprecated. Returns the table name of field. Use mysql_query() instead
mysql_thread_id() Returns the current thread ID
mysql_unbuffered_query() Executes a query on a MySQL database (without fetching / buffering the result)
 

Comments

Popular posts from this blog

MySQL Connection

Connection with MySQL Database Before accessing database, you must create a connection to the database Syntax: mysql_connect(servername,username,password); where, servername specifies the server to connect to. Default value is “localhost” username specifies the username to log in with. Default value is the name of the user that owns the server process. To connect offline we use username “root”. password specifies the password to log in with. Default is “” Code : Creating connection to the database and selecting the required database <?php $con = mysql_connect(“localhost”,”root”,”"); if (!$con) { die(‘Could not connect: ‘ . mysql_error()); } else{ mysql_select_db(“test”, $con) }; ?> Here, we have store connection in a variable called $con and trap error using die function. Closing connection The connection will be closed automatically when the script ends. To close the connection before, use the mysql_close() function: <?php $con = mysql_conne...

Type Juggling and Type Casting

Type Juggling: PHP does not require (or support) explicit type definition in variable declaration; a variable's type is determined by the context in which the variable is used. That is to say, if a string value is assigned to variable $var, $var becomes a string. If an integer value is then assigned to $var, it becomes an integer.

Doctype Defination

A Document Type Declaration, or DOCTYPE, is an instruction that associates a particular SGML or XML document (for example, a webpage) with a Document Type Definition (DTD). Syntax The general syntax for a document type declaration is: <!DOCTYPE root-element PUBLIC "FPI" ["URI"] [ <!-- internal subset declarations --> ]>