Basic settings of MySQL_real_connect in MySQL database

Source: Internet
Author: User

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

 
 
  1. * User,
  2. Const char * passwd, const char * db, unsigned int port, const char * unix_socket,
  3. Unsigned long client_flag)
  4. Description
  5. MySQL (best combination with PHP) _ real_connect () attempts to establish a connection to a MySQL (best combination with PHP) database engine
  6. Running on host. MySQL (the best combination with PHP) _ real_connect () must complete successfully before you can
  7. Execute any other API functions that require a valid MySQL (the best combination with PHP) connection handle structure.
  8. The parameters are specified as follows:
  9. *
  10. The first parameter shocould be the address of an existing MySQL (best combination with PHP) structure. Before
  11. 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)
  12. Structure. You can change a lot of connect options with the MySQL (the best combination with PHP) _ options () call.
  13. See Section  17.2.3.47,  "MySQL (the best combination with PHP) _ options ()  ".
  14. *
  15. The value of host may be either a hostname or an IP address. If host is NULL or
  16. String "localhost", a connection to the local host is assumed. If the OS supports sockets
  17. (Unix) or named pipes (Windows), they are used instead of TCP/IP to connect to the server.
  18. *
  19. The user parameter contains the user's MySQL (the best combination with PHP) login ID. If user is NULL or The empty
  20. String "", the current user is assumed. Under Unix, this is the current login name. Under
  21. Windows ODBC, the current username must be specified explicitly. See Section  18.1.9.2,
  22.  Configuring a MyODBC DSN on Windows  ".
  23. *
  24. The passwd parameter contains the password for user. If passwd is NULL, only entries
  25. In the user table for the user that have a blank (empty) password field are checked for
  26. Match. This allows the database administrator to set up the MySQL (best combination with PHP) privilege system in
  27. Such a way that users get different privileges depending on whether they have specified
  28. A password.
  29. Note: Do not attempt to encrypt the password before calling MySQL (the best combination with PHP) _ real_connect ();
  30. Password encryption is handled automatically by the client API.
  31. *
  32. Db is the database name. If db is not NULL, the connection sets the default database
  33. To this value.
  34. *
  35. If port is not 0, the value is used as the port number for the TCP/IP connection. Note
  36. That the host parameter determines the type of the connection.
  37. *
  38. If unix_socket is not NULL, the string specifies the socket or named pipe that shoshould
  39. Be used. Note that the host parameter determines the type of the connection.
  40. *
  41. The value of client_flag is usually 0, but can be set to a combination of the following
  42. 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.

 
 
  1. Flag Name Flag Description
  2. CLIENT_COMPRESS Use compression protocol.
  3. CLIENT_FOUND_ROWS Return the number of found (matched) rows, not the number
  4. Changed rows.
  5. CLIENT_IGNORE_SPACE Allow spaces after function names. Makes all functions names
  6. Reserved words.
  7. CLIENT_INTERACTIVE Allow interactive_timeout seconds (instead of wait_timeout
  8. Seconds) of inactivity before closing the connection. The client's session wait_timeout
  9. Variable is set to the value of the session interactive_timeout variable.
  10. CLIENT_LOCAL_FILES Enable load data local handling.
  11. CLIENT_MULTI_STATEMENTS Tell the server that the client may send multiple
  12. Statements in a single string (separated by  '; Â'). If this flag is not set,
  13. Multiple-statement execution is disabled. Added in MySQL (the best combination with PHP) 4.1.
  14. CLIENT_MULTI_RESULTS Tell the server that the client can handle multiple result
  15. Sets from multiple-statement executions or stored procedures. This is automatically
  16. Set if CLIENT_MULTI_STATEMENTS is set. Added in MySQL (the best combination with PHP) 4.1.
  17. CLIENT_NO_SCHEMA Don't allow the db_name.tbl_name.col_name syntax. This is
  18. ODBC. It causes the parser to generate an error if you use that syntax, which is useful
  19. For trapping bugs in some ODBC programs.
  20. CLIENT_ODBC The client is an ODBC client. This changes MySQL (The best combination with PHP) d to be more
  21. ODBC-friendly.
  22. CLIENT_SSL Use SSL (encrypted protocol). This option shocould not be set
  23. Application programs; it is set internally in the client library. Instead, use
  24. MySQL (the best combination with PHP) _ ssl_set () before calling MySQL (the best combination with PHP) _ real_connect ().
  25. For some parameters, it is possible to have the value taken from an option file rather
  26. Than from an explicit value in the MySQL (the best combination with PHP) _ real_connect () call. To do this, call
  27. 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
  28. Before calling MySQL (the best combination with PHP) _ real_connect (). Then, in the MySQL (the best combination with PHP) _ real_connect () call, specify
  29. The  "no-value Â" value for each parameter to be read from an option file:
  30. *
  31. For host, specify a value of NULL or the empty string ("").
  32. *
  33. For user, specify a value of NULL or the empty string.
  34. *
  35. For passwd, specify a value of NULL. (For the password, a value of the empty string in
  36. The MySQL (best combination with PHP) _ real_connect () call cannot be overridden in an option file, because the empty
  37. String indicates explicitly that the MySQL (best combination with PHP) account must have an empty password .)
  38. *
  39. For db, specify a value of NULL or the empty string.
  40. *
  41. For port, specify a value of 0.
  42. *
  43. For unix_socket, specify a value of NULL.
  44. If no value is found in an option file for a parameter, its default value is used
  45. Indicated in the descriptions given earlier in this section.
  46. Return Values
  47. A MySQL (best combination with PHP) * connection handle if the connection was successful, NULL if the connection
  48. Was unsuccessful. For a successful connection, the return value is the same as the value
  49. 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.

 
 
  1. Errors
  2. *
  3. CR_CONN_HOST_ERROR
  4. Failed to connect to the MySQL (the best combination with PHP) server.
  5. *
  6. CR_CONNECTION_ERROR
  7. Failed to connect to the local MySQL (the best combination with PHP) server.
  8. *
  9. CR_IPSOCK_ERROR
  10. Failed to create an IP socket.
  11. *
  12. CR_OUT_OF_MEMORY
  13. Out of memory.
  14. *
  15. CR_SOCKET_CREATE_ERROR
  16. Failed to create a Unix socket.
  17. *
  18. CR_UNKNOWN_HOST
  19. Failed to find the IP address for the hostname.
  20. *
  21. CR_VERSION_ERROR
  22. A protocol mismatch resulted from attempting to connect to a server with a client
  23. Library that uses a different protocol version. This can happen if you use a very old
  24. Client library to connect to a new server that wasn' t started with the -- old-protocol
  25. Option.
  26. *
  27. CR_NAMEDPIPEOPEN_ERROR
  28. Failed to create a named pipe on Windows.
  29. *
  30. CR_NAMEDPIPEWAIT_ERROR
  31. Failed to wait for a named pipe on Windows.
  32. *
  33. CR_NAMEDPIPESETSTATE_ERROR
  34. Failed to get a pipe handler on Windows.
  35. *
  36. CR_SERVER_LOST
  37. If connect_timeout> 0 and it took longer than connect_timeout seconds to connect
  38. 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.

Related Article

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.