PHP mysqli How to connect MySQL database _php tutorial

Source: Internet
Author: User
Tags php and mysql
In learning 1. Launch API support for PHP

(1) First modify the configuration file of your php.ini.
Look for the following statement:
; Extension=php_mysqli.dll
Modify it to:
Extension=php_mysqli.dll

(2) Restart the Apache/iis, you can.

(3) Description: PHP needs a separate file to support this extension library, generally in the PHP directory in the EXT directory can find php_mysqli.dll files (php <= 5.0.2 is Libmysqli.dll), of course, in the PHP configuration file should have the correct point to ext information (EXTENSION_DIR). If your PHP does not have this file, you can download the PHP5 source package. In addition, this API extension can only be used in versions above PHP5. For other specific information, please see below.

2.PHP mysqli ID

MYSQLI is the abbreviation for "MySQL, improved", which applies only to PHP 5. It can be used for MySQL 4.1.1 and later versions. The extension fully supports the authentication protocol used in MySQL 5.1, and also supports preprocessing statements and multi-statement APIs. In addition, the extension provides an advanced, object-oriented programming interface.

3. MYSQLI pre-defined classes

Mysqli

The connection between PHP and MySQL database is expressed.

constructor function

Mysqli-Constructs a new PHP mysqli object

Method

Autocommit-turn on or turn off the auto-submit database option
Change_user-the user who changed the specified database connection
Character_set_name-Returns the default character set for the database connection
Close-Closes a previously opened connection
Commit-Commit the current transaction
Connect-Opens a new connection to the MySQL database server
Debug-Perform an error-handling operation
Dump_debug_info-Get the wrong information
Get_client_info-Returns the client version
Get_host_info-Returns the type used by the connection
Get_server_info-Returns the version of the MySQL server
Get_server_version-Returns the version of the MySQL server
init-Initialize PHP mysqli object
Info-Get information about the most recently executed query
Kill-Requires the server to stop a MySQL thread
Multi_query-Execute multiple queries
More_results-check If more results exist from currently executed Multi-query
Next_result-reads next result from currently executed Multi-query
Options-set Options
Ping-pings a server connection or reconnects if there is no connection
Prepare-prepares a SQL query
Query-performs a query
Real_connect-attempts to open a connection to MySQL database server
Escape_string-escapes special characters in a string for use in a SQL statement, taking to account the current charset of the connection
Rollback-rolls back the current transaction
Select_db-selects the default database
Set_charset-sets The default client character set
Ssl_set-sets SSL Parameters
Stat-gets the current system status
Stmt_init-initializes a statement for use with Mysqli_stmt_prepare
Store_result-transfers a resultset from last query
Thread_safe-returns whether thread safety is given or not
Use_result-transfers an unbuffered resultset from last query

Property

Affected_rows-gets the number of affected rows in a previous MySQL operation
Client_info-returns the MySQL client version as a string
Client_version-returns the MySQL client version as an integer
Errno-returns the "error code for the" recent function call
Error-returns the error string for the most recent function call
Field_count-returns the number of columns for the most recent query
Host_info-returns A string representing the type of connection used
Info-retrieves information about the most recently executed query
Insert_id-returns the auto generated ID used in the last query
Protocol_version-returns the version of the MySQL protocol used
Server_info-returns A string that represents the server version number
Server_version-returns The version number of the server as an integer
Sqlstate-returns A string containing the SQLSTATE error code for the last error
Thread_id-returns the thread ID for the current connection
Warning_count-returns the number of warnings generated during execution of the previous SQL statement

4. Basic Syntax

 
 
  1. Php
  2. /* Connect to a MySQL server connection database server */
  3. $ Link = Mysqli_connect (
  4. ' localhost ',/* The host to connect to connection to the MySQL address */
  5. ' User ',/* The user to connect as connection MySQL username */
  6. ' Password ',/* The password to use connect mysql password */
  7. ' World '); /* The default database to query connects to the DB name */
  8. if (! $link) {
  9. printf ("Can ' t connect to MySQL Server. Errorcode:%s ", Mysqli_connect_error ());
  10. Exit
  11. }
  12. /* Send a query to the server sends a request to the servers */
  13. if ($result = mysqli_query($link, ' SELECT Name, Population from City ORDER by Population DESC LIMIT 5 ')) {
  14. Print ("Very Large Cities is:");
  15. /* Fetch The results of the query results */
  16. While ($row = mysqli_fetch_assoc($result)) {
  17. printf ("%s (%s)", $row [' Name '], $row [' Population ']);
  18. }
  19. /* Destroy The result set and free memory used for it end query
  20. Mysqli_free_result ($result);
  21. }
  22. /* Close the connection connection */
  23. Mysqli_close ($link);
  24. ?>

The solutions described above can help us easily solve the problem of PHP mysqli connection database.


http://www.bkjia.com/PHPjc/446385.html www.bkjia.com true http://www.bkjia.com/PHPjc/446385.html techarticle in learning 1. Enable PHP API support (1) First modify your php.ini configuration file. Look for the following statement:; Extension=php_mysqli.dll modify it to: Extension=php_mysqli.dll ...

  • 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.