MySQL Database function Library _mysql

Source: Internet
Author: User
Tags numeric php and php and mysql phpmyadmin
This function library is available to access the MySQL database. For details about MySQL, and download the MySQL database, please go to this URL http://www.mysql.com. And on the network also has many to provide the processing MySQL user interface program, recommends to the Http://www.phpwizard.net/phpMyAdmin downloading phpMyAdmin, may use the browser operation and manages the MySQL. The whole set of phpMyAdmin procedures, is completed with PHP3, can also study the PHP3 and MySQL link.

Mysql_affected_rows: Gets the number of columns affected by the MySQL last operation.
Mysql_close: Shut down the MySQL server connection.
Mysql_connect: Open the MySQL server connection.
mysql_create_db: Create a new MySQL database.
Mysql_data_seek: Moves the internal return pointer.
Mysql_db_query: Send query string to MySQL database.
mysql_drop_db: Removing the database.
Mysql_errno: Returns the error message code.
Mysql_error: Returns an error message.
Mysql_fetch_array: Returns the array data.
Mysql_fetch_field: Get field information.
Mysql_fetch_lengths: Returns the maximum length of column data in a single column.
Mysql_fetch_object: Return class data.
Mysql_fetch_row: Returns the individual fields of a single column.
Mysql_field_name: Returns the name of the specified field.
Mysql_field_seek: Configures a pointer to a field that returns a value.
Mysql_field_table: Gets the table name for the current field.
Mysql_field_type: Gets the type of the current field.
Mysql_field_flags: Gets the flag for the current field.
Mysql_field_len: Gets the length of the current field.
Mysql_free_result: Free back to occupy memory.
MYSQL_INSERT_ID: Returns the ID for the last time the insert instruction was used.
Mysql_list_fields: Lists the fields (field) for the specified table.
Mysql_list_dbs: Lists the databases (database) available for the MySQL server.
Mysql_list_tables: Lists the table (table) for the specified database.
Mysql_num_fields: Gets the number of returned fields.
Mysql_num_rows: Gets the number of returned columns.
Mysql_pconnect: Open MySQL Server continuous connection.
Mysql_query: Send out a query string.
Mysql_result: Gets the results of the query.
mysql_select_db: Select a database.
Mysql_tablename: Gets the table name.

Mysql_affected_rows
The number of columns affected by the last operation of MySQL.
Syntax: int mysql_affected_rows (int [link_identifier]);
return value: Integer
Function Type: Database function
Description: This function can get the number of columns (row) affected by INSERT, UPDATE, or DELETE for the MySQL final query operation. If the last query (query) uses delete and the WHERE command is not used, all data is deleted and this function returns 0. If the last use of SELECT, then use this function will not get the expected number, because to change the MySQL database This function is valid, want to get the number returned by select to use the Mysql_num_rows () function.

Mysql_close
Close the MySQL server connection.
Syntax: int mysql_close (int [link_identifier]);
return value: Integer
Function Type: Database function
Description: This function closes the connection to the MySQL database server. If no parameter link_identifier is specified, the last connection is closed. You cannot use this function to close with a mysql_pconnect () connection. In fact, this function is not necessarily necessary, when the full page of PHP after the end of the program, will automatically shut down the database and the non-permanent (non-persistent) connection. Return true successfully, failure returns false value.
Reference: mysql_connect () Mysql_pconnect ()

Mysql_connect
Open the MySQL server connection.
Syntax: int mysql_connect (string [hostname] [:p ort], string [username], string [password]);
return value: Integer
Function Type: Database function
Content Description: This function establishes the connection with the MySQL server. All of these parameters can be omitted. When using this function without any arguments, the default value of the parameter hostname is localhost, the default value for the parameter username is the owner of the PHP execution stroke, and the parameter password is an empty string (that is, no password). and the parameter hostname can be followed by colon and port number, the representative uses that port and MySQL connection. Of course, when using a database, using Mysql_close () to turn off the connection early can save resources.
Usage examples
This is a sample provided by an unnamed Netizen (18-feb-1999)
<?php
$DBH = mysql_connect (' localhost:3306 ', ' McClain ', ' standard ');
mysql_select_db (' Admreqs ');
$query = "INSERT into requests (date, request, email, priority,status) VALUES (now (), ' $description ', ' $email ', ' $priority ' , ' NEW ') ';
$res = mysql_query ($query, $DBH);
$query = "SELECT Max (ID) from requests";
$res = mysql_query ($query, $DBH);
$err = Mysql_error ();
if ($err) {
echo "Error occurred, please notify <a href=mailto:webmaster@my.site> webmaster </a>";
}
$row = Mysql_fetch_row ($res);
echo "The number you use in the future is:". $row [0];
?>
Reference: Mysql_close () Mysql_pconnect ()

mysql_create_db
Create a new MySQL database.
Syntax: int mysql_create_db (string database name, int [link_identifier]);
return value: Integer
Function Type: Database function
Content Description: This function is used to create a new database. You must connect to the server before you can establish it.
Reference: mysql_drop_db ()

Mysql_data_seek
Moves the internal return pointer.
Syntax: int mysql_data_seek (int result_identifier, int row_number);
return value: Integer
Function Type: Database function
Content Description: This function can move the internal returned column pointer to the specified row_number. The value of the new column can then be returned using Mysql_fetch_row (). Return true successfully, False if failed.

Mysql_db_query
Send query string to MySQL database.
Syntax: int mysql_db_query (string database, string query, int [link_identifier]);
return value: Integer
Function Type: Database function
Content Description: This function is used to send out query string (queries) to the MySQL database in the backend. But the omitted parameter Link_identifier if does not exist, the program will automatically look for other mysql_connect () The connection code after the connection. Returns False when an error occurs, and returns its return code when there is no error.
Reference: mysql_connect ()

mysql_drop_db
Remove the database.
Syntax: int mysql_drop_db (string database_name, int [link_identifier]);
return value: Integer
Function Type: Database function
Content Description: This function removes an existing database. Return true successfully, False if failed.
Reference: mysql_create_db ()

Mysql_errno
Returns the error message code.
Syntax: int mysql_errno (int [link_identifier]);
return value: Integer
Function Type: Database function
Content Description: This function can get the MySQL database server error code. Usually used in the PHP Web program development phase, as a debugging of PHP and MySQL.
Usage examples
<?php
Mysql_connect ("Marliesle");
Echo Mysql_errno (). ":". Mysql_error (). <BR> ";
mysql_select_db ("Nonexistentdb");
Echo Mysql_errno (). ":". Mysql_error (). <BR> ";
$conn = mysql_query ("SELECT * from nonexistenttable");
Echo Mysql_errno (). ":". Mysql_error (). <BR> ";
?>
Reference: Mysql_error ()

Mysql_error
Returns an error message.
Syntax: string mysql_error (int [link_identifier]);
return value: String
Function Type: Database function
Content Description: This function can get the MySQL database server error message. Usually used in the PHP Web program development phase, with Mysql_errno () together as PHP and MySQL debugging.
Reference: Mysql_errno ()

Mysql_fetch_array
Returns the array data.
Syntax: array mysql_fetch_array (int result, int [Result_typ]);
return value: Array
Function Type: Database function
Description: This function is used to split query result results into an array variable. Returns the value of False if result has no data. This function can be said to be a mysql_fetch_row (), in addition to the return column and the numeric index can be placed in the array, you can also put the text index into the array. If several return fields are the same literal name, the last placed field is valid by using a numeric index or by alias (alias) for Fields (column) with the same name.  pay attention to the use of this function can not be processed faster than the Mysql_fetch_row () function slow, which function to use or to see the needs of the use of the decision. The parameter Result_typ is a constant value with the following constants Mysql_assoc, Mysql_num, and Mysql_both.
Usage examples
<?php
Mysql_connect ($host, $user, $password);
$result = mysql_db_query ("Database", "SELECT * from table");
while ($row = Mysql_fetch_array ($result)) {
echo $row ["user_id"];
echo $row ["FullName"];
}
Mysql_free_result ($result);
?>

Mysql_fetch_field
Gets the field information.
Syntax: Object Mysql_fetch_field (int result, int [field_offset]);
Return value: Class
Function Type: Database function
Content Description: The class data returned by this function is the field (Column) information for result. The properties of the returned class are as follows:
Name-Field names
Table-table name of the table in which the field is located
Max_length-Maximum length of field
Not_null-If 1 indicates that this field cannot be empty (null)
Primary_key-If 1 indicates this field is the primary key (primary key)
Unique_key-If 1 indicates that this field is not a repeat key (unique key)
Multiple_key-If 1 indicates that this field is a repeating key (Non-unique key)
Numeric-If 1 indicates that this field is a numeric type (numeric)
Blob-If 1 indicates that this field is a bit type (BLOB)
Type-field type
Unsigned-if 1 indicates this field is unmarked (unsigned)
Zerofill-If 1 means the field is filled with 0 (zero-filled)
Reference: Mysql_field_seek ()

Mysql_fetch_lengths
Returns the maximum length of column data in a single column.
Syntax: array mysql_fetch_lengths (int result);
return value: Array
Function Type: Database function
Description: This function puts the maximum length of each field data of the last column processed by Mysql_fetch_row () in the array variable. Returns the value of False if execution fails. The first Data index value for the returned array is 0.
Reference: Mysql_fetch_row ()

Mysql_fetch_object
Returns the class data.
Syntax: Object mysql_fetch_object (int result, int [Result_typ]);
Return value: Class
Function Type: Database function
Description: This function is used to split query result results into class variables. The use method is almost the same as mysql_fetch_array (), except that the return data for this function is a class rather than an array. Returns the value of False if result has no data. In addition to the  pay attention to the place is, retrieve the class data index can only be text and can not use numbers, this is because of the characteristics of the class. All property names in attributes of class data cannot be numbers, so you have to use literal strings as indexes. The parameter Result_typ is a constant value with the following constants Mysql_assoc, Mysql_num, and Mysql_both. With regard to speed, the processing speed of this function is almost the same as that of Mysql_fetch_row () and mysql_fetch_array () two functions, which function to use or to see the requirements of the use of the decision.
Usage examples
The following example demonstrates the use of the returned class.
<?php
Mysql_connect ($host, $user, $password);
$result = Mysql_db_query ("MyDatabase", "SELECT * from Test");
while ($row = Mysql_fetch_object ($result)) {
Echo $row->user_id;
Echo $row->fullname;
}
Mysql_free_result ($result);
?>
Reference: Mysql_fetch_array () mysql_fetch_row ()

Mysql_fetch_row
Returns the individual fields of a single column.
Syntax: array mysql_fetch_row (int result);
return value: Array
Function Type: Database function
Description: This function is used to disassemble the result of query results into an array variable. The index of an array is a numeric index, and the first index value is 0. Returns the value of False if result has no data.
Reference: Mysql_fetch_array () mysql_fetch_object () Mysql_data_seek () mysql_fetch_lengths () mysql_result ()

Mysql_field_name
Returns the name of the specified field.
Syntax: string mysql_field_name (int result, int field_index);
return value: String
Function Type: Database function
Content Description: This function is used to get the name of the specified field.
Usage examples
Mysql_field_name ($result, 2);

Mysql_field_seek
Configure the pointer to return a  a field.
Syntax: int mysql_field_seek (int result, int field_offset);
return value: Integer
Function Type: Database function
Description: This function configures the current pointer to a specific field in the return .
Reference: Mysql_fetch_field ()

Mysql_field_table
Gets the name of the table for the current field.
Syntax: string mysql_field_table (int result, int field_offset);
return value: String
Function Type: Database function
Content Description: This function can get the table name of the field currently in.

Mysql_field_type
Gets the type of the current field.
Syntax: string mysql_field_type (int result, int field_offset);
return value: String
Function Type: Database function
Content Description: This function can get the current type of field format. The returned string is the type of the field, including int, real, string, blob .... And so on, see MySQL related files in the section on the type.
Usage examples
<?php
Mysql_connect ("localhost:3306");
mysql_select_db ("Wisconsin");
$result = mysql_query ("SELECT * from Onek");
$fields = Mysql_num_fields ($result);
$rows = mysql_num_rows ($result);
$i = 0;
$table = mysql_field_table ($result, $i);
echo "Table". $table. "' There '. $fields." Column and ". $rows." <br> ";
echo "The fields in this table are as follows <br>";
while ($i < $fields) {
$type = Mysql_field_type ($result, $i);
$name = Mysql_field_name ($result, $i);
$len = Mysql_field_len ($result, $i);
$flags = Mysql_field_flags ($result, $i);
echo $type. " ". $name." ". $len." ". $flags." <br> ";
$i + +;
}
Mysql_close ();
?>

Mysql_field_flags
Gets the flags for the current field.
Syntax: string mysql_field_flags (int result, int field_offset);
return value: String
Function Type: Database function
Content Description: This function can get the current field of the flag. If a field has several attribute flags, the returned flags are strings attached to these properties, each of which is separated by a space, and can be explode () to cut the strings. The flags returned may be: Not_null, Primary_key, Unique_key, Multiple_key, blob, unsigned, zerofill, binary, enum, auto_increment, Timestamp

Mysql_field_len
Gets the length of the current field.
Syntax: int mysql_field_len (int result, int field_offset);
return value: Integer
Function Type: Database function
Content Description: This function can get the length of the current field.

Mysql_free_result
Release returns memory consumption.
Syntax: boolean mysql_free_result (int result);
Return Value: Boolean value
Function Type: Database function
Content Description: This function can release the current MySQL database query to return the memory occupied. This function is typically used only if you are very concerned about the likelihood that the memory may not be sufficient for use. The PHP program is automatically released at the end.

mysql_insert_id
Returns the ID for the last time the INSERT instruction was used.
Syntax: int mysql_insert_id (int [link_identifier]);
return value: Integer
Function Type: Database function
Description: This function can get the last execution ID using INSERT to MySQL database. Sleibowitz@btcwcu.org (13-may-1999) points out that you can use this function to obtain an ID in the PHP 3.0.7 version using REPLACE as well as using INSERT.

Mysql_list_fields
Lists the fields (field) for the specified table.
Syntax: int mysql_list_fields (string database_name, string table_name, int [link_identifier]);
return value: Integer
Function Type: Database function
Description: This function can get all the fields of the specified table. The field information returned can be used by functions such as mysql_field_flags (), Mysql_field_len (), Mysql_field_name (), and Mysql_field_type (). Return-1 If there is an error.

Mysql_list_dbs
Lists the databases (database) available for the MySQL server.
Syntax: int mysql_list_dbs (int [link_identifier]);
return value: Integer
Function Type: Database function
Content Description: This function can get the MySQL server available database.

Mysql_list_tables
Lists the tables (table) for the specified database.
Syntax: int mysql_list_tables (string database, int [link_identifier]);
return value: Integer
Function Type: Database function
Content Description: This function can get all the table names in the specified database.

Mysql_num_fields
Gets the number of returned fields.
Syntax: int mysql_num_fields (int result);
return value: Integer
Function Type: Database function
Content Description: This function can get the number of returned fields.
Reference: Mysql_db_query () mysql_query () Mysql_fetch_field () mysql_num_rows ()

Mysql_num_rows
Gets the number of returned columns.
Syntax: int mysql_num_rows (int result);
return value: Integer
Function Type: Database function
Content Description: This function can get the number of returned columns.
Reference: Mysql_db_query () mysql_query () mysql_fetch_row ()

Mysql_pconnect
Open the MySQL server for continuous connection.
Syntax: int mysql_pconnect (string [hostname] [:p ort], string [username], string [password]);
return value: Integer
Function Type: Database function
Content Description: This function and mysql_connect () is identical. The difference is that when you open a database using this function, the program first looks for whether the function has been executed, and returns the previously executed ID if executed. Another difference is that this function cannot close the database using Mysql_close ().

Mysql_query
Send out a query string.
Syntax: int mysql_query (string query, int [link_identifier]);
return value: Integer
Function Type: Database function
Content Description: This function sends out query string for MySQL to do related processing or execution. If you do not specify the Link_identifier parameter, the program automatically looks for the most recently opened ID. When the query string is UPDATE, INSERT, and DELETE, the return may be true or false, and the query's string is a SELECT to return the new ID value. Joey@samaritan.com (09-feb-1999) indicates that when false, it is not a successful execution but no return value, but rather a query string with errors.
Reference: Mysql_db_query () mysql_select_db () mysql_connect ()

Mysql_result
Gets the results of the query.
Syntax: int mysql_result (int result, int row, mixed field);
return value: Integer
Function Type: Database function
Description: This function gets the result of a grid query. The parameter field can be a field name, order, or fieldname.tablename format. This function can be used to handle the amount of data returned. When the database is large, the efficiency of this function is to be considered, then the more efficient mysql_fetch_row (), mysql_fetch_array () and mysql_fetch_object () functions can be used.

mysql_select_db
Select a database.
Syntax: int mysql_select_db (string database_name, int [link_identifier]);
return value: Integer
Function Type: Database function
Content Description: This function selects the database in the MySQL server for later data query Job (query) processing. Returns true successfully, and returns False if failed.
Reference: mysql_connect () Mysql_pconnect () mysql_query ()

Mysql_tablename
Gets the table name.
Syntax: string mysql_tablename (int result, int i);
return value: String
Function Type: Database function
Description: This function can get the table name string, generally with the mysql_list_tables () function, get the number of the letter returned by the name string.
Usage examples
<?php
Mysql_connect ("localhost:3306");
$result = Mysql_list_tables ("Wisconsin");
$i = 0;
while ($i < mysql_num_rows ($result)) {
$TB _names[$i] = Mysql_tablename ($result, $i);
echo $TB _names[$i]. "<BR>";
$i + +;
}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.