MySQL database Function Details _ MySQL

Source: Internet
Author: User
Author: OSO osuo (1? Intmysql_affected_rows ([intlink_id]); in a given connection, the number of rows affected by the last DELETE, INSERT, REPLACE, or UPDATE statement is returned. If no row is modified, mysql_affected_rows () returns 0. If an error occurs,-1 is returned. After the SELECT query, mysql_affected_r author: I want OSO osso (1? Int mysql_affected_rows ([int link_id]);
In a given connection, the number of rows affected by the last DELETE, INSERT, REPLACE, or UPDATE statement is returned. If no rows exist

If mysql_affected_rows () is modified, 0 is returned. If an error occurs,-1 is returned.
After the SELECT query, mysql_affected_rows () returns the selected number of rows. However, it is generally used together with the SELECT statement.

Mysql_num_rows ().

Example:
<? Php
$ Link = mysql_pconnect ("localhost", "sunsoft", "suixiang") or die ("cocould not connect ");
Mysql_select_db ("samp_db") or die ("cocould not select database ");
$ Query = "INSERT

Member (last_name, first_name, expiration) "." VALUES ('brown ', 'Marcia', '2017-6-3 ')";
$ Result = mysql_query ($ query) or die ("Query failed ");
Printf ("% d row % s insertedn", mysql_affected_rows (), mysql_affected_rows () = 1? "": "S ");
?>


(2) int mysql_close (int [link_id]);
Close the connection to the MySQL server identified by link_id. If no connection is specified, mysql_close () closes the recently opened connection.

. If the call succeeds, mysql_close () returns true, and false if the call fails. For a permanent connection opened by mysql_pconnect,

Mysql_close () ignores the corresponding close request, but only returns the value. To close a connection, use mysql_connect () instead

Mysql_pconnect () to open it.

Example:

<? Php
$ Link = mysql_connect ("localhost", "sunsoft", "suixiang") or die ("cocould not connect ");
Print ("Connected successfully ");
Mysql_close ($ link );
?>


(3) int mysql_connect (string [hostname] [: port], string [username], string [password]);
This function establishes a connection with the MySQL server. All parameters can be omitted. When you use this function without adding any parameters

The internal value of several hostnames is localhost, the internal value of the parameter username is the owner of the PHP execution itinerary, and the parameter password is

It is a null string (no password ). The hostname parameter can be followed by a colon and port number, indicating that the port is used to connect to MySQL. Of course in

When using a database, you can use mysql_close () to turn off the connections earlier to save resources.


Example


This is an example provided by an anonymous user (18-Feb-1999)
<? Php
$ Dbh = mysql_connect ('localhost: 808080', 'mcclain', 'standard ');
Mysql_select_db ('admreqs ');
$ Query = "insert into requests (date, request, email, priority, status) values

(NOW (), '$ description',' $ email ',' $ priority ', 'new ')";
$ Res = mysql_query ($ query, $ dbh );
$ Query = "select max (id) from requests ";
$ Res = mysql_query ($ query, $ dbh );
$ Err = mysql_error ();
If ($ err ){
Echo "an error occurred, please notify <a href = mailto: webmaster@my.site> webmaster </a> ";
}
$ Row = mysql_fetch_row ($ res );
Echo "Your future number is:". $ row [0];
?>


(4) int mysql_create_db (string db_name [, int link_id]);
Tells the MySQL server identified by link_id to create a database with the given name. If the database is successfully created, true is returned. for example:

If an error occurs, false is returned. You must have the CREATE permission to CREATE a database.
The use of mysql_query () may be more suitable than the use of mysql_create_db () to publish the create database statement.
<? Php
$ Link = mysql_pconnect ("localhost", "sunsoft", "suixiang"); or die ("cocould not connect ");
If (mysql_create_db ("my_db "))
Print ("Database created successfullyn ");
Else
Print ("Error creating database: % sn", mysql_error ());
?>

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.