Name
mysql_change_user
Synopsis
int mysql_change_user( stringusername
, stringpassword
[, stringdatabase
[, cresourceconnection
]])
Changes the logged-in MySQL user to
another username
using that
user’s password
. Optional
database
and
connection
resource handles may be
specified. If the database
and
connection
resource handles are omitted,
the current database and most recently opened connection that is
still open are assumed.
The function returns true
on success and
false
on failure. If false
is
returned, the user that was authenticated prior to the function call
remains current.
Warning
The function mysql_change_user( )
is available
only through MySQL DBMS Version 3.23.3 and later. In addition, the
function is missing from PHP Version 4 (up to and including the
current PHP 4.1.2), with calls to the function reporting it as an
undefined function. This is likely to be fixed in future PHP
versions.
Example
<?php $connection = mysql_connect("localhost", "fred", "shhh"); mysql_select_db("wedding", $connection); // The database will still be "wedding" on the current connection if (mysql_change_user("richo", "twelve") == true) echo "Changed user to richo"; else echo "Change to user richo failed!"; ?>
Get Managing & Using MySQL, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.