mysql| Function | data | database | detailed (1) int mysql_affected_rows ([int link_id]);
Returns the number of rows that are acting on the most recent delete, INSERT, replace, or UPDATE statement in a given connection. If there is no line
is modified, the Mysql_affected_rows () returns 0, and if an error occurs, returns-1.
After a select query, Mysql_affected_rows () returns the number of rows selected. But is typically used with a SELECT statement
Mysql_num_rows ().
Use Example:
<?php
$link =mysql_pconnect ("localhost", "Sunsoft", "Suixiang") or Die ("could not Connect");
mysql_select_db ("samp_db") or Die ("could not select Database");
$query = "INSERT into
Member (Last_name,first_name,expiration) "." VALUES (' Brown ', ' Marcia ', ' 2002-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]);
Closes the connection to the MySQL server identified by link_id. If no connection is specified, Mysql_close () closes the recently opened
Pick up. If successful, the Mysql_close () returns True, and the failure returns false. For permanent connections opened by Mysql_pconnect (),
Mysql_close () ignores the appropriate shutdown request, but returns the value. If you want to close a connection, you should use mysql_connect () instead
Mysql_pconnect () to open it.
Use Example:
<?php
$link =mysql_connect ("localhost", "Sunsoft", "Suixiang") or Die ("could not Connect");
Print ("Connected successfully");
Mysql_close ($link);
?>
(3) int mysql_connect (string [hostname] [:p ort], string [username], string [password]);
This function establishes a connection to the MySQL server. All of these parameters can be omitted. When you use this function without any arguments, the parameter
The default value of number hostname is localhost, the default value of parameter username is the owner of PHP execution Stroke, and the parameter password
is an empty string (that is, no password). and the parameter hostname can be followed by colon and port number, the representative uses that port and MySQL connection. Of course in
When using a database, using Mysql_close () early to turn off the line can save resources.
Usage examples
This is a sample provided by an unnamed Netizen (18-feb-1999)
<?php
$DBH = mysql_connect (' localhost:3306 ', ' 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 "Error occurred, please notify <a href=mailto:webmaster@my.site> webmaster </a>";
}
$row = Mysql_fetch_row ($res);
echo "The number you use in the future is:". $row [0];
?>
(4) int mysql_create_db (string db_name [, int link_id]);
Tells the MySQL server identified by link_id to create the database with the given name. Returns true if the database is created successfully;
If an error occurs, it returns false. The Create permission must be created in the database.
It may be more appropriate to use mysql_query () to publish a CREATE DATABASE statement using mysql_create_db ().
<?php
$link =mysql_pconnect ("localhost", "Sunsoft", "Suixiang"); Or Die ("could not Connect");
if (mysql_create_db ("my_db"))
Print ("Database created Successfullyn");
Else
Print ("Error creating Database:%sn", mysql_error ());
?>