Phpmysqli entry application implementation _ PHP Tutorial

Source: Internet
Author: User
Phpmysqli entry application implementation. The mysqli extension of php is encapsulated into a class, which is an object-oriented technology with faster execution speed, compared with traditional procedural methods, mysqli is more convenient and efficient. by default, mysqli is the mysqli extension of php and is encapsulated into a class. it is an object-oriented technology, faster execution, more convenient and efficient than traditional procedural methods

By default, mysqli is not enabled in php.
To use mysqli extension in PHP, add the following settings in the configuration file php. ini:

The code is as follows:
Extension = php_mysqli.dll

If the preceding settings are already in the configuration file, make sure there is no ";" before extension; otherwise, remove it. The following describes how to use the mysqli extension to access the database.

The code is as follows:
$ Db_host = "localhost"; // address of the connected server
$ Db_user = "root"; // username used to connect to the database
$ Db_psw = "root"; // database connection password
$ Db_name = "sunyang"; // name of the connected database
$ Mysqli = new mysqli ();
$ Mysqli-> connect ($ db_host, $ db_user, $ db_psw, $ db_name );
?>

Close the connection with the MySQL server and call the close () method through the mysqli object. for example:
$ Mysqli-> close ();

The code is as follows:

$ Connection = mysqli_connect ("localhost", "root", "root", "sunyang ");
If ($ connection ){
Echo "database connection successful ";
} Else {
Echo "database connection failed ";
}
?>

Data Query

The code is as follows:

$ Mysqli = new mysqli ("localhost", "root", "root", "sunyang"); // instantiate mysqli
$ Query = "select * from employee ";
$ Result = $ mysqli-> query ($ query );
If ($ result ){
If ($ result-> num_rows> 0) {// determines whether the number of rows in the result set is greater than 0
While ($ row = $ result-> fetch_array () {// records in the cyclic output result set
Echo ($ row [0])."
";
Echo ($ row [1])."
";
Echo ($ row [2])."
";
Echo ($ row [3])."
";
Echo "";
}
}
} Else {
Echo "query failed ";
}
$ Result-> free ();
$ Mysqli-> close ();
?>

Other image data storage waiting


Member methods in the mysqli class

_ Construct (): Constructor used to create a mysqli object and establish a connection.

Autocommit (): Enables or disables automatic submission of database modifications.

Change_user (): change the user specified by the database connection.

Character_set_name (): returns the default character set for database connection.

Close (): close the previously opened connection.

Commit (): submit the current transaction.

Connect (): open a new connection to the mysql database server.

Debug (): execute the debugging operation.

Dump_debug_info (): dump debugging information.

Get_client_info (): returns the client version.

Get_host_info (): returns the connection usage type represented by a string, for example, Localhost via UNIX socket.

Get_server_info (): returns the mysql server version.

Get_server_version (): returns the mysql server version in integer format.

Init (): initializes a mysqli and returns a resource.

Info (): Searches for recently executed queries.

Kill (): kill a mysql thread.

Multi_query (): execute multiple query statements.

More_results (): retrieves more query results from multiple query statements.

Next_result (): Read the next result from the currently executed multi-query.

Options (): Set options.

Ping (): If there is no connection, ping a server to connect or reconnect.

Prepare (): prepare the execution of an SQL statement and return the mysqli_stmt object.

Query (): queries are used to interact with the database. this method sends queries to the database for execution. if the execution fails, FALSE is returned.

Real_connect (): attempts to open a connection to the mysql database server.

Escape_string (): Escape special character string.

Rollback (): rolls back the current transaction.

Select_db (): Select a default database for database query.

Set_charset (): sets the default client character set.


Ssl_set (): Use ssl to establish a secure connection.

Stat (): Gets the current system status.

Stmt_init (): initializes a declaration and returns a mysql_stmt object.

Store_result (): transfers the result set from the final query.

Thread_safe (): whether to consider returning a secure thread.


Member attributes in the mysql class

$ Affected_rows: number of rows affected by the previous mysql operation.

$ Client_info: mysql client version (string ).

$ Client_version: mysql client version (integer ).

$ Errno: the error code of the latest function call.

$ Error: string of the error message of the latest function call.

$ Field_count (): number of columns obtained by the query.

$ Host_info: the connection type (string ).

$ Info: The latest query.

$ Insert_id: The number automatically generated in the last query.

$ Protocol_version: version used by the mysql protocol.

$ Sqlstate: The Last error that contains the SQLSTATE error code.

$ Thread_id: ID of the current connection thread.

$ Warning_count: number of warnings generated during execution of the previous SQL statement.

By default, mysqli in php is...

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.