This article mainly tells you about the basic settings of MySQL_real_connect connection parameters in the MySQL database. In the previous article, we talked about how to use MySQL (the best combination with PHP) the source code compilation link, but does not tell the running situation, after compiling and running according to the code of the previous article.
It is found that the database file cannot be linked, which is obviously a problem in the MySQL (the best combination with PHP) _ real_connect function. Find the following description about MySQL (the best combination with PHP) _ real_connect () in the English manual of MySQL (the best combination with PHP:
Function prototype description MySQL database * MySQL (the best combination with PHP) _ real_connect (MySQL (the best combination with PHP) * MySQL (the best combination with PHP ), const char * host, const char
- * User,
- Const char * passwd, const char * db, unsigned int port, const char * unix_socket,
- Unsigned long client_flag)
- Description
- MySQL (best combination with PHP) _ real_connect () attempts to establish a connection to a MySQL (best combination with PHP) database engine
- Running on host. MySQL (the best combination with PHP) _ real_connect () must complete successfully before you can
- Execute any other API functions that require a valid MySQL (the best combination with PHP) connection handle structure.
- The parameters are specified as follows:
- *
- The first parameter shocould be the address of an existing MySQL (best combination with PHP) structure. Before
- Calling MySQL (the best combination with PHP) _ real_connect () you must call MySQL (the best combination with PHP) _ init () to initialize the MySQL (the best combination with PHP)
- Structure. You can change a lot of connect options with the MySQL (the best combination with PHP) _ options () call.
- See Section  17.2.3.47,  "MySQL (the best combination with PHP) _ options ()  ".
- *
- The value of host may be either a hostname or an IP address. If host is NULL or
- String "localhost", a connection to the local host is assumed. If the OS supports sockets
- (Unix) or named pipes (Windows), they are used instead of TCP/IP to connect to the server.
- *
- The user parameter contains the user's MySQL (the best combination with PHP) login ID. If user is NULL or The empty
- String "", the current user is assumed. Under Unix, this is the current login name. Under
- Windows ODBC, the current username must be specified explicitly. See Section  18.1.9.2,
-  Configuring a MyODBC DSN on Windows  ".
- *
- The passwd parameter contains the password for user. If passwd is NULL, only entries
- In the user table for the user that have a blank (empty) password field are checked for
- Match. This allows the database administrator to set up the MySQL (best combination with PHP) privilege system in
- Such a way that users get different privileges depending on whether they have specified
- A password.
- Note: Do not attempt to encrypt the password before calling MySQL (the best combination with PHP) _ real_connect ();
- Password encryption is handled automatically by the client API.
- *
- Db is the database name. If db is not NULL, the connection sets the default database
- To this value.
- *
- If port is not 0, the value is used as the port number for the TCP/IP connection. Note
- That the host parameter determines the type of the connection.
- *
- If unix_socket is not NULL, the string specifies the socket or named pipe that shoshould
- Be used. Note that the host parameter determines the type of the connection.
- *
- The value of client_flag is usually 0, but can be set to a combination of the following
- Flags to enable certain features:
The main values of the five parameters are described above. MySQL database * is the pointer returned by the _ init function for MySQL (the best combination with PHP, when the host is null or // localhost, it is linked to a local computer. when MySQL (the best combination with PHP) is installed on a unix or unix-like system by default, the root account does not have a password. Therefore, the user name is root and the password is null. When the database is empty, the function is linked to the default database, the default test database exists during the installation of // MySQL (the best combination with PHP). Therefore, you can use the test database name and port 0 here, use the // unix connection mode. If the unix_socket is null, it indicates no socket or pipeline mechanism is used. The last parameter is often set to 0.
- Flag Name Flag Description
- CLIENT_COMPRESS Use compression protocol.
- CLIENT_FOUND_ROWS Return the number of found (matched) rows, not the number
- Changed rows.
- CLIENT_IGNORE_SPACE Allow spaces after function names. Makes all functions names
- Reserved words.
- CLIENT_INTERACTIVE Allow interactive_timeout seconds (instead of wait_timeout
- Seconds) of inactivity before closing the connection. The client's session wait_timeout
- Variable is set to the value of the session interactive_timeout variable.
- CLIENT_LOCAL_FILES Enable load data local handling.
- CLIENT_MULTI_STATEMENTS Tell the server that the client may send multiple
- Statements in a single string (separated by  '; Â'). If this flag is not set,
- Multiple-statement execution is disabled. Added in MySQL (the best combination with PHP) 4.1.
- CLIENT_MULTI_RESULTS Tell the server that the client can handle multiple result
- Sets from multiple-statement executions or stored procedures. This is automatically
- Set if CLIENT_MULTI_STATEMENTS is set. Added in MySQL (the best combination with PHP) 4.1.
- CLIENT_NO_SCHEMA Don't allow the db_name.tbl_name.col_name syntax. This is
- ODBC. It causes the parser to generate an error if you use that syntax, which is useful
- For trapping bugs in some ODBC programs.
- CLIENT_ODBC The client is an ODBC client. This changes MySQL (The best combination with PHP) d to be more
- ODBC-friendly.
- CLIENT_SSL Use SSL (encrypted protocol). This option shocould not be set
- Application programs; it is set internally in the client library. Instead, use
- MySQL (the best combination with PHP) _ ssl_set () before calling MySQL (the best combination with PHP) _ real_connect ().
- For some parameters, it is possible to have the value taken from an option file rather
- Than from an explicit value in the MySQL (the best combination with PHP) _ real_connect () call. To do this, call
- MySQL (the best combination with PHP) _ options () with the MySQL (the best combination with PHP) _ READ_DEFAULT_FILE or MySQL (the best combination with PHP) _ READ_DEFAULT_GROUP option
- Before calling MySQL (the best combination with PHP) _ real_connect (). Then, in the MySQL (the best combination with PHP) _ real_connect () call, specify
- The  "no-value Â" value for each parameter to be read from an option file:
- *
- For host, specify a value of NULL or the empty string ("").
- *
- For user, specify a value of NULL or the empty string.
- *
- For passwd, specify a value of NULL. (For the password, a value of the empty string in
- The MySQL (best combination with PHP) _ real_connect () call cannot be overridden in an option file, because the empty
- String indicates explicitly that the MySQL (best combination with PHP) account must have an empty password .)
- *
- For db, specify a value of NULL or the empty string.
- *
- For port, specify a value of 0.
- *
- For unix_socket, specify a value of NULL.
- If no value is found in an option file for a parameter, its default value is used
- Indicated in the descriptions given earlier in this section.
- Return Values
- A MySQL (best combination with PHP) * connection handle if the connection was successful, NULL if the connection
- Was unsuccessful. For a successful connection, the return value is the same as the value
- Of the first parameter.
Return Value: If the connection is successful, the MySQL database connection handle is returned. If the connection fails, NULL is returned. When the request succeeds, the return value is the same as the value of the first parameter.
- Errors
- *
- CR_CONN_HOST_ERROR
- Failed to connect to the MySQL (the best combination with PHP) server.
- *
- CR_CONNECTION_ERROR
- Failed to connect to the local MySQL (the best combination with PHP) server.
- *
- CR_IPSOCK_ERROR
- Failed to create an IP socket.
- *
- CR_OUT_OF_MEMORY
- Out of memory.
- *
- CR_SOCKET_CREATE_ERROR
- Failed to create a Unix socket.
- *
- CR_UNKNOWN_HOST
- Failed to find the IP address for the hostname.
- *
- CR_VERSION_ERROR
- A protocol mismatch resulted from attempting to connect to a server with a client
- Library that uses a different protocol version. This can happen if you use a very old
- Client library to connect to a new server that wasn' t started with the -- old-protocol
- Option.
- *
- CR_NAMEDPIPEOPEN_ERROR
- Failed to create a named pipe on Windows.
- *
- CR_NAMEDPIPEWAIT_ERROR
- Failed to wait for a named pipe on Windows.
- *
- CR_NAMEDPIPESETSTATE_ERROR
- Failed to get a pipe handler on Windows.
- *
- CR_SERVER_LOST
- If connect_timeout> 0 and it took longer than connect_timeout seconds to connect
- The server or if the server died while executing the init-command.
Therefore, MySQL (the best combination with PHP) _ real_connect () function call is:
MySQL (best combination with PHP) _ real_connect (MySQL database, "localhost", "root", NULL, "test", 0, NULL, 0 );
Determines whether an error occurs. When an error occurs, call the MySQL (best combination with PHP) _ error () function to display the error information, or use MySQL (the best combination with PHP) _ errno () function to obtain the error code.