PHP mysqli Entry Application implementation

Source: Internet
Author: User
Tags character set commit error code mysql client php and mysql database

By default mysqli is not open in PHP and we need to
To use mysqli extensions in PHP, you need to add the following settings to the configuration file php.ini:

The code is as follows Copy Code
Extension=php_mysqli.dll

If the configuration file already has the above settings, make sure the extension is not preceded by ";" or remove it. Here's how to use the mysqli extension to access the database.

The code is as follows Copy Code
<?php
$db _host= "localhost"; The server address of the connection
$db _user= "root"; User name to connect to database
$db _psw= "root"; Password to connect to the database
$db _name= "Sunyang"; Database name of the connection
$mysqli =new mysqli ();
$mysqli->connect ($db _host, $db _user, $db _psw, $db _name);
?>

Shut down the connection to the MySQL server by calling the close () method with the Mysqli object, for example:
$mysqli->close ();

The code is as follows Copy Code

<?php
$connection = Mysqli_connect ("localhost", "root", "root", "Sunyang");
if ($connection) {
echo "Database connection succeeded";
}else {
echo "Database connection failed";
}
?>

Data query

The code is as follows Copy Code

<?php
$mysqli =new mysqli ("localhost", "root", "root", "Sunyang"); Instantiation of Mysqli
$query = "SELECT * FROM Employee";
$result = $mysqli->query ($query);
if ($result) {
if ($result->num_rows>0) {//Determine if the number of rows in the result set is greater than 0
while ($row = $result->fetch_array ()) {//Loops output records in a result set
Echo ($row [0]). " <br> ";
Echo ($row [1]). " <br> ";
Echo ($row [2]). " <br> ";
Echo ($row [3]). " <br> ";
echo "}
}
}else {
echo "Query failed";
}
$result->free ();
$mysqli->close ();
?>

Other like data save wait


Member methods in the Mysqli class

__construct (): Constructs a method to create a Mysqli object, or to establish a connection.

Autocommit (): Turn on or off database modification autocommit.

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

Character_set_name (): Returns the database connection default character set.

Close (): Closes a previously opened connection.

Commit (): Commit the current thing.

Connect (): Open a new connection to the MySQL database server.

Debug (): Perform debugging operations.

Dump_debug_info (): Dumps debugging information.

Get_client_info (): Returns the client version.

Get_host_info (): Returns a String representing the type of connection used, such as: Localhost via UNIX socket

Get_server_info (): Returns the MySQL server version.

Get_server_version (): Returns the MySQL server version in integer form.

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

Info (): Retrieves the most recently executed query.

Kill (): kills a MySQL thread.

Multi_query (): Executes multiple query statements.

More_results (): Retrieves any more query results from a multiple query statement.

Next_result (): reads the next result from the currently executing multiple query.

Options (): Sets the option.

Ping (): Ping a server to connect or reconnect if there is no connection.

Prepare (): Prepares the execution of an SQL statement, returning the Mysqli_stmt object.

Query (): Interaction with a database is done through a query that sends a query to the database to execute, and the execution fails to return false.

Real_connect (): Attempting to open a connection to the MySQL database server.

Escape_string (): A string that escapes special characters.

Rollback (): Rolls back the current transaction.

select_db (): Select a default database for the database query.

Set_charset (): Sets the default client character set.


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

Stat (): Gets the current system state.

Stmt_init (): Initializes a declaration that returns a Mysql_stmt object.

Store_result (): Transfer the result set from the last query.

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


member properties in the MySQL class

$affected _rows: The number of rows affected in the previous MySQL operation.

$client _info:mysql Client version (string).

$client _version:mysql Client version (integer).

$errno: The error code for the most recent function call.

$error: The error message string for the most recent function call.

$field _count (): The number of columns fetched by the query.

$host _info: The connection type is used (a string).

$info: Recently executed query.

$insert _id: The number that was automatically generated by the last query.

$protocol the version used by the _version:mysql protocol.

$sqlstate: The last error containing the SQLSTATE error code.

$thread _id: Current connection thread ID.

$warning _count: The number of warnings generated during the execution of the previous SQL statement.

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.