MySQL related instructions_PHP tutorial
Resource Types
There are two resource types used in the MySQL module. The first is the connection handle of the database, and the second is the result set returned by the SQL query.
Predefined constants
The following constants are defined by this extension module, so they are only valid after this extension module is compiled into PHP or is dynamically loaded at runtime.
In PHP 4.3.0 and later versions, more client tags are allowed to be specified in the mysql_connect() function and mysql_pconnect() function. The defined constants are listed below:
Table 2. MySQL client constants
Constant Description
MYSQL_CLIENT_COMPRESS uses compressed communication protocol
MYSQL_CLIENT_IGNORE_SPACE allows spaces after the function name
MYSQL_CLIENT_INTERACTIVE allows setting the interactive_timeout time to wait idle before disconnecting (instead of wait_timeout).
MYSQL_CLIENT_SSL uses SSL encryption. This flag is only available when the MySQL client library version is 4.x or higher. Both PHP 4 and Windows version of PHP 5 installation packages are bundled with 3.23.x. The
mysql_fetch_array() function uses a constant to represent the type of the returned array. The following is the definition of constants:
Table 3. MySQL fetch constants
Constant Description
MYSQL_ASSOC The data column returned uses the field name as the index name of the array.
MYSQL_BOTH The data column returned uses the field name and numeric index as the index name of the array.
MYSQL_NUM The data column returned uses a numeric index as the index name of the array. The index starts at 0 , indicating the first field of the returned result.
Notes
Note: Most MySQL functions accept link_identifier as the last optional parameter. If this parameter is not provided, the last open connection is used. If a connection does not exist, the default parameters defined in php.ini will be used to try to establish a connection. If the connection is unsuccessful, the function returns FALSE.
Example
The following simple example demonstrates how to connect to the database, execute query statements, print the returned result set and disconnect from the database and a series of basic MySQL operations. 例子 1. MySQL 例子
// 连接,选择数据库
$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')
or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('my_database') or die('Could not select database');
// 执行 SQL 查询
$query = 'Select * FROM my_table';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
// 用 HTML 显示结果
echo "
$col_value | n";
// Release the result set
mysql_free_result($result);
// Close the connection
mysql_close($link ; User
mysql_client_encoding -- Returns the name of the character set
mysql_close -- Closes the MySQL connection
mysql_connect -- Opens a connection to the MySQL server
mysql_create_db -- Creates a new MySQL database
mysql_data_seek -- Move the internal result pointer
mysql_db_name -- Get the result data
mysql_db_query -- Send a MySQL query
mysql_drop_db -- Drop (delete) a MySQL database
mysql_errno -- Return the previous MySQL operation Numeric encoding of the error message
mysql_error -- Returns the text error message generated by the previous MySQL operation
mysql_escape_string -- Escapes a string for mysql_query
mysql_fetch_array -- Gets a row from the result set as an associative array, Or a numeric array, or both
mysql_fetch_assoc -- Get a row from the result set as an associative array
mysql_fetch_field -- Get column information from the result set and return it as an object
mysql_fetch_lengths -- Get each row in the result set The length of the output
mysql_fetch_object -- Get a row from the result set as an object
mysql_fetch_row -- Get a row from the result set as an enumeration array
mysql_field_flags -- Get the flags associated with the specified field from the result
mysql_field_len -- Return the length of the specified field
mysql_field_name -- Get the field name of the specified field in the result
mysql_field_seek -- Set the pointer in the result set to the specified field offset
mysql_field_table -- Get the specified The name of the table where the field is located
mysql_field_type -- Get the type of the specified field in the result set
mysql_free_result -- Release the result memory
mysql_get_client_info -- Get the MySQL client information
mysql_get_host_info -- Get the MySQL host information
mysql_get_proto_info -- Get MySQL protocol information
mysql_get_server_info -- Get MySQL server information
mysql_info -- Get the latest query information
mysql_insert_id -- Get the ID generated by the previous Insert operation
mysql_list_d bs -- List all databases in the MySQL server
mysql_list_fields -- List the fields in the MySQL results
mysql_list_processes -- List the MySQL processes
mysql_list_tables -- List the tables in the MySQL database
mysql_num_fields -- Get the number of fields in the result set
mysql_num_rows -- Get the number of rows in the result set
mysql_pconnect -- Open a persistent connection to the MySQL server
mysql_ping -- Ping a server connection, reconnect if there is no connection
mysql_query -- Send a MySQL query
mysql_real_escape_string -- Escape special characters in the string used in the SQL statement, taking into account the current character set of the connection
mysql_result -- Get the result data
mysql_select_db -- Select the MySQL database
mysql_stat -- Get the current system status
mysql_tablename -- Get the table name
mysql_thread_id -- Return the ID of the current thread
mysql_unbuffered_query -- Send a SQL query to MySQL and not Line to get and cache results
http://www.bkjia.com/PHPjc/317799.html
www.bkjia.com
true

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.

The main difference between MySQL and MariaDB is performance, functionality and license: 1. MySQL is developed by Oracle, and MariaDB is its fork. 2. MariaDB may perform better in high load environments. 3.MariaDB provides more storage engines and functions. 4.MySQL adopts a dual license, and MariaDB is completely open source. The existing infrastructure, performance requirements, functional requirements and license costs should be taken into account when choosing.

SQL is a standard language for managing relational databases, while MySQL is a database management system that uses SQL. SQL defines ways to interact with a database, including CRUD operations, while MySQL implements the SQL standard and provides additional features such as stored procedures and triggers.

MySQL and phpMyAdmin can be effectively managed through the following steps: 1. Create and delete database: Just click in phpMyAdmin to complete. 2. Manage tables: You can create tables, modify structures, and add indexes. 3. Data operation: Supports inserting, updating, deleting data and executing SQL queries. 4. Import and export data: Supports SQL, CSV, XML and other formats. 5. Optimization and monitoring: Use the OPTIMIZETABLE command to optimize tables and use query analyzers and monitoring tools to solve performance problems.

Redis is a memory data structure storage system, mainly used as a database, cache and message broker. Its core features include single-threaded model, I/O multiplexing, persistence mechanism, replication and clustering functions. Redis is commonly used in practical applications for caching, session storage, and message queues. It can significantly improve its performance by selecting the right data structure, using pipelines and transactions, and monitoring and tuning.

In MySQL, add fields using ALTERTABLEtable_nameADDCOLUMNnew_columnVARCHAR(255)AFTERexisting_column, delete fields using ALTERTABLEtable_nameDROPCOLUMNcolumn_to_drop. When adding fields, you need to specify a location to optimize query performance and data structure; before deleting fields, you need to confirm that the operation is irreversible; modifying table structure using online DDL, backup data, test environment, and low-load time periods is performance optimization and best practice.
