- int mysql_change_user(string
user
, stringpassword
, [stringdatabase
, [resourceconnection
]]) -
Changes the logged-in MySQL user to another
user
, using that user'spassword
for an optionally specifieddatabase
andconnection
. If omitted, the current database and most recently opened connection are assumed. Returnsfalse
on failure and, if it does fail, the previous, successful connection stays current. - int mysql_create_db(string
db
, [resourceconnection
]) -
Creates a database named
db
using theconnection
resource returned from amysql_connect( )
function call or the last-opened connection if the parameter is omitted. - int mysql_drop_db(string
db
, [resourceconnection
]) -
Drops a database named
db
using theconnection
resource returned from amysql_connect( )
function call or the last-opened connection if the parameter is omitted. - object mysql_fetch_field(resource
result_set
, [intattribute_number
]) -
Returns as an object the metadata for each attribute associated with a
result_set
resource returned from a query function call. An optionalattribute_number
can be specified to retrieve the metadata associated with a specific attribute. However, repeated calls process the attributes one by one.The properties of the
object
returned by the function are:- name
-
The attribute name
- table
-
The name of the table that the attribute belongs to
- max_length
-
The maximum length of the attribute
- not_null
-
Set to 1 if the attribute can't be
NULL
- primary_key
-
Set to 1 if the attribute forms part of a primary key
- unique_key
-
Set to 1 if the attribute is a unique key
- multiple_key
-
Set to 1 if the attribute is a nonunique key
- numeric
-
Set to 1 if the attribute is a numeric type
- blob
-
Set to 1 if the attribute is a
BLOB
type - type
-
The type of the attribute
- unsigned
-
Set to 1 if the attribute is an unsigned numeric type
- zerofill
-
Set to 1 if the numeric column is zero-filled
Example 4-3 is a script that uses the
mysql_fetch_field()
function to emulate most of the behavior of theSHOW COLUMNS
orDESCRIBE
commands discussed in Chapter 3. The code uses the same five-step query process discussed earlier, with the exception thatmysql_fetch_field( )
is used in place ofmysql_fetch_row( )
. Sample output for the table wine is shown in Example 4-4. The same result could have been achieved by executingDESCRIBE WINE
on the winestore database usingmysql_query( )
and retrieving the results withmysql_fetch_object( )
.This function also has other uses. For example, it can be used in validation-the subject of Chapter 7-to check whether the data entered by a user is longer than the maximum length of the database attribute. Indeed, a script can be developed that automatically performs basic validation based on the table structure.
Other functions
by
updated