Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

The mysql_affected_rows function returns the number of rows affected by the last
query made to the specified database connection link. If the link argument is omitted,
the last-opened connection is assumed. If the last query was an unconditional delete, zero
will be returned. If you want to know how many rows were returned by a select
statement, use mysql_num_rows.


<?
//connect to server as freetrade user, no password
$dbLink = mysql_pconnect("localhost", "freetrade", "");


//select the 'freetrade' database
mysql_select_db("freetrade", $dbLink);


//update some invoices
$Query = "UPDATE invoice ".
"SET Active = 'Y' ".
"WHERE ID 100 ";
$dbResult = mysql_query($Query, $dbLink);


//let user know how many rows were updated
$AffectedRows = mysql_affected_rows($dbLink);
print("$AffectedRows rows updated.
\n");
?>


boolean mysql_change_user(string user, string password,
string database, integer link)


Use mysql_change_user to change the user for a database connection. The database
and link arguments are optional. If left out, the current database and the link last opened
are used. If the user cannot be changed, the current connection remains open with the
original user. This function requires MySQL version 3.23.3 or newer.


<?
//connect to server as freetrade user, no password
$dbLink = mysql_pconnect("localhost", "freetrade", "");


//select the 'freetrade' database
mysql_select_db("freetrade", $dbLink);


//switch to admin user
mysql_change_user("admin", "secret", "freetrade", $dbLink);
?>


boolean mysql_close(integer link)

Free download pdf