MySQL PHP

MySQL is a relational database with a license that allows you to use it cost-free for most noncommercial purposes. It shares many features with mSQL because it was originally conceived as a faster, more flexible replacement. Indeed, MySQL has delivered on these goals. It easily outperforms even commercial databases. Not surprisingly, MySQL is the database of choice for many PHP developers. To find out more about MySQL, as well as obtain source code and binaries. There are plenty of mirrors to aid your download speed. Be sure to check out the excellent online manual. As with mSQL, there were MySQL functions in PHP2 that are still supported in PHP3, but their use is discouraged. I've chosen to leave these functions out of the reference. The functions I've left out are mysql, mysql_cre- atedb, mysql_dbname, mysql_dropdb, mysql_fieldflags, mysql_field-len, mysql_fieldname, mysql_fieldtable, mysql_fieldtype, mysql_ freeresult, mysql_listdbs, mysql_listfields, mysql_listtables, mysql_numfields, mysql_numrows, mysql_selectdb, mysql_tablename. The MySQL extension was written by Zeev Suraski.

integer mysql_affected_rows(integer link)
The mysql_affected_rows function returns the number of rows affected by the last query made to the specified database connection link. If the link argument is omitted, the last-opened connection is assumed. If the last query was an unconditional delete, zero will be returned. If you want to know how many rows were returned by a select statement, use mysql_num_rows.

boolean mysql_change_user(string user, string password, string database, integer link)
Use mysql_change_user to change the user for a database connection. The database and link arguments are optional. If left out, the current database and the link last opened are used. If the user cannot be changed, the current connection remains open with the original user. This function requires MySQL version 3.23.3 or newer.

boolean mysql_close(integer link)
Use mysql_close to close the connection to a database. The connect must have been opened with mysql_connect. Use of this function is not strictly necessary, as all nonpersistent links are closed automatically when the script finishes. The link argument is optional, and when it's left out, the connection last opened is closed.

integer mysql_connect(string host, string user, string password)
The mysql_connect function begins a connection to a MySQL database at the specified host. If the database is on a different port, follow the hostname with a colon and a port number. You may alternatively supply a colon and the path to a socket if connecting to localhost. This might be written as localhost:/tmp/sockets/mysql. All the arguments are optional and will default to localhost, the name of the user executing the script, and an empty string, respectively. The user executing the script is typically httpd, the Web server. Connections are automatically closed when a script finishes execution, though they may be closed earlier with mysql_close. If you attempt to open a connection that is already open, a second connection will not be made. The identifier of the previously open connection will be returned. FALSE is returned in the event of an error.

boolean mysql_create_db(string database, integer link)
Use mysql_create_db to create a new database. Note that you must open a connection with an account that has permission to create databases. If you leave out the link argument, the last-opened connection will be used.

boolean mysql_data_seek(integer result, integer row)
The mysql_data_seek function moves the internal row pointer of a result set to the specified row. Use this function with mysql_fetch_row to jump to a specific row. The result argument must have been returned from mysql_query or a similar function.

integer mysql_db_query(string database, string query, integer link)
The mysql_db_query function executes a query on the specified database and returns a result identifier. If the link argument is omitted, the last-opened link will be used, or a new one will be created if necessary.

boolean mysql_drop_db(string database, integer link)
Use mysql_drop_db to delete a database. If the link argument is omitted, the lastopened link will be used.

integer mysql_errno(integer link)
The mysql_errno function returns the error number of the last database action. If the optional link identifier is left out, the last connection will be assumed.

string mysql_error(integer link)
Use mysql_error to get the textual description of the error for the last database action. If the optional link identifier is left out, the last connection will be assumed.

array mysql_fetch_array(integer result, integer type)
The mysql_fetch_array function returns an array that represents all the fields for a row in the result set. Each call produces the next row until no rows are left, in which case FALSE is returned. By default, each field value is stored twice: once indexed by offset starting at zero and once indexed by the name of the field. This behavior can be controlled with the type argument. If the MYSQL_NUM constant is used, elements will be indexed by field numbers only. If the MYSQL_ASSOC constant is used, elements will be index by field names only. You can also use MYSQL_BOTH to force the default. Compare this function to mysql_fetch_object and mysql_fetch_row.

array mysql_fetch_array(integer result, integer type)

mysq1_fetch_arrayobject mysql_fetch_field(integer result, integer field)
Fields are numbered starting with zero. The return value is an object with properties described. If the field argument is left out, the next field in the set will be returned. This behavior allows you to loop through each field easily.

mysq1_fetch_arrayobject mysql_fetch_field(integer result, integer field)

array mysql_fetch_lengths(integer result)
Use mysql_fetch_lengths to get an array of the maximum lengths for each of the fields in a result set.

object mysql_fetch_object(integer result)
The mysql_fetch_object function is similar to mysql_fetch_array and mysql_fetch_row. Instead of an array, it returns an object. Each field in the result set is a property in the returned object. Each call to mysql_fetch_object returns the next row, or FALSE if there are no rows remaining. This allows you to call mysql_fetch_object in the test condition of a while loop to get every row.

array mysql_fetch_row(integer result)
The mysql_fetch_row function returns an array that represents all the fields for a row in the result set. Each call produces the next row until no rows are left, in which case FALSE is returned. Each field value is indexed numerically, starting with zero. Compare this function to mysql_ fetch_array and mysql_fetch_object. There isn't much difference in performance between these three functions.

string mysql_field_flags(integer result, integer field)
Use mysql_field_flags to get a description of the flags on the specified field. The flags are returned in a string and separated by spaces. The flags you can expect are auto_increment, binary, blob, enum, multiple_key, not_null, primary_key, timestamp, unique_key, unsigned, and zerofill. Some of these flags may be available only in the newest versions of MySQL. See mysql_list_fields for an example of use.

integer mysql_field_len(integer result, integer field)
Use mysql_field_len to get the maximum number of characters to expect from a field. The fields are numbered from zero. See mysql_list_fields for an example of use.

string mysql_field_name(integer result, integer field)
Use mysql_field_name to get the name of a column. The field argument is an offset numbered from zero. See mysql_list_fields for an example of use.

boolean mysql_field_seek(integer result, integer field)
The mysql_field_seek function moves the internal field pointer to the specified field. The next call to mysql_fetch_field will get information from this field. See mysql_list_fields for an example of use.

string mysql_field_table(integer result, integer field)
The mysql_field_table function returns the name of the table for the specified field. If an alias is used, as in the example below, the alias is returned.

string mysql_field_type(integer result, integer field)
Use mysql_field_type to get the type of a particular field in the result set.

boolean mysql_free_result(integer result)
Use mysql_free_result to free any memory associated with the specified result set. This is not strictly necessary, as this memory is automatically a freed when a script finishes executing.

integer mysql_insert_id(integer link)
After inserting into a table with an auto_increment field, the mysql_insert_id function returns the id assigned to the inserted row. If the link argument is left out, the most recent connection will be used.

integer mysql_list_dbs(integer link)
The mysql_list_dbs function queries the server for a list of databases. It returns a result pointer that may be used with mysql_fetch_row and similar functions.

integer mysql_list_fields(string database, string table, integer link)
The mysql_list_fields function returns a result pointer to a query on the list of fields for a specified table. The result pointer may be used with any ofthe functions that get information about columns in a result set: mysql_field_flags, mysql_field_len, mysql_field_name, mysql_field_type. The link argument is optional.

mysq1_list_fields

mysq1_list_fields

mysq1_list_fields

integer mysql_list_tables(string database, integer link)
Use mysql_list_tables to get a result pointer to a list of tables for a specified database. The result pointer may be used in any of the functions for fetching rows from a result set. The link argument is optional.

integer mysql_num_fields(integer result) The mysql_num_fields function returns the number of fields in a result set. See mysql_list_fields for an example of use.

integer mysql_num_rows(integer result)
The msyql_num_rows function returns the number of rows in a result set. See mysql_result for an example of use.

integer mysql_pconnect(string host, string user, string password)
The mysql_pconnect function operates like mysql_connect except that the connection will be persistent. That is, it won't be closed when the script ends. The connection will last as long as the server process lasts, so that if a connection is attempted later from the same process, the overhead of opening a new connection will be avoided.

A link identifier is returned.

This identifier is used in many of the other functions in this section.

integer mysql_query(string query, integer link)<pre>Use mysql_query to execute a query. If the link argument is omitted, the last connection made is used. If there has been no previous connection, PHP will connect to the local host. If the query performs an insert, delete, or update, a boolean value will be returned. Select queries return a result identifier. See mysql_fetch_object for an example of use.</pre>

string mysql_result(integer result, integer row, string field)

The mysql_result function returns the value of the specified field in the specified row. The field argument may be a number, in which case it is onsidered a field offset. It may also be the name of a column, either with the table name or without. It could also be an alias. In general, this function is very slow.

It's better to use mysql_fetch_row or a similar function.

boolean mysql_select_db(string database, integer link)

Use mysql_select_db to select the default database. Most of the other examples in this section use mysql_select_db.

« Previous Topics
Sybase
Oracle
Odbc
Next Topics »
Msql
Inter Base
Postgres

Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

PHP Topics