phpMySqlConnection

Last modified: 7/12/2002 3:32PM GMT-6:00

phpMySqlConnection is a class that helps use the mysql_* functions of PHP with a friendly interface and a rich feature set. The functions are named with a slightly less difficult way to memorize, plus many of the methods in this class offer a quick way to do related calls to perform your task. Below are brief descriptions of each method included within the class.

phpMySqlConnection

phpMySqlConnection ( [ $user [ ,$pass [ ,$host [ ,$port [ ,$socket_path ] ] ] ] ] )

This is the class constructor. On success you will have a new object that will allow you use the methods & variables of this class. It attempts to log into $host through $port / $socket_path using $user and $pass. Returns an error message in case of a failure, otherwise returns the integer 1.

GetDatabases

GetDatabases ( )

Get a list of the available databases on the current server. On success an array indexed by number of the databases available is returned. On success, an array of database names that the user has access to is returned. Else returns an error string.

CreateDB

CreateDB ( $database)

Create a database named $database on the server. On success returns the integer 1, else returns an error string. Also sets $obj->a_rows, which is the output of mysql_affected_rows ( ).

DropDB

DropDB ( $database)

Drop the database named $database from the server. Careful, this deletes all the information within the database; this is not what you'd use for a backup! On success returns the integer 1, else returns an error string. Also sets $obj->a_rows, which is the output of mysql_affected_rows ( ).

CopyDB

CopyDB ( $database, [ $dest_db [ ,$drop_tables [ ,$dest_host [ ,$dest_user [ ,$dest_pass [ ,$dest_port [ ,$dest_socket_path ] ] ] ] ] ] ] )

This function allows you to copy the database named $database to one named $dest_db on $dest_host:$dest_port using $dest_user / $dest_pass over $dest_socket. Setting $drop_tables to 1 will cause the database to overwrite the target if it exists. On success returns the integer 1, else returns an error string.

CopyTable

CopyTable ( $table,$dest_table,$database,$dest_db, [ $drop_table [ ,$conn_id [ ,$dest_host [ ,$dest_user [ ,$dest_pass [ ,$dest_port [ ,$dest_socket_path ] ] ] ] ] ] ] )

This function allows you to copy the table named $table to one named $dest_table in $dest_db on $dest_host:$dest_port using $dest_user / $dest_pass over $dest_socket. Setting $drop_tables to 1 will cause the database to overwrite the target if it exists. On success returns the integer 1, else returns an error string.

SelectDB

SelectDB ( $db)

Select or change your working database to $db. On success returns the integer 1, else returns an error string.

GetTableList

GetTableList ( )

Get a list of the available tables in the current working database. On success returns an array of table names that the user can access, else returns an error string.

GetFieldList

GetFieldList ( $tbl_name)

Get a list of the fields names in the table named $tbl_name of the current database. On success returns an array of the field names of the table, else returns an error string.

Delete

Delete ( $query)

Execute a deletion query. On success returns the integer 1, else returns an error string. Also sets $obj->a_rows, which is the output of mysql_affected_rows ( ).

Update

Update ( $query)

Execute an update query. On success returns the integer 1, else returns an error string. Also sets $obj->a_rows, which is the output of mysql_affected_rows ( ).

Insert

Insert ( $query)

Execute an insertion query. On success returns the integer 1, else returns an error string. Also sets $obj->a_rows, which is the output of mysql_affected_rows ( ).

InsertID

InsertID ( )

Get last insert id from an auto_incremented field. Returns the id on success, or an error string on failure.

Query

Query ( $query)

Execute a query that may return more than one row. On success returns the integer 1, else returns an error string.

GetRow

GetRow ( $row)

Get row number $row of data from a multiple row query. This is useful when using loops to retrieve data. On success returns the integer 1, else returns an error string. Also sets the $obj->data array indexed by number and field name with the result.

QueryRow

QueryRow ( $query)

Execute a query that returns only one row. On success returns an array containing the data indexed by column number and field name, else returns an error string. Also sets the $obj->data array indexed by number and field name with the result.

QueryItem

QueryItem ( $query)

Execute a query that returns only one element. On success returns the value queried, else returns an error string. Also sets the $obj->data array indexed by number and field name with the result.

XML_DataOutput

QueryItem ( $query [ ,array ( 'dataset_tag', 'recordset_tag' ) )

Get an XML representation of the resultant recordset data. Returns the XML data including the header, sets $this->data without the header (XML tags only).

Exists

Exists ( $query)

Check if a query returns a result. Returns TRUE on existance, or FALSE on non-existance. Also sets the other class elements the same way that Query ( ) does.

GetSetList

GetSetList ( $table,$field)

Andrew Collington - Sets the $obj->data array indexed by number and field name with its value.

GetEnumList

GetEnumList ( $table,$field)

Andrew Collington - Sets the $obj->data array indexed by enum element name with its value.

errorMessage

mysql_ErrorMsg ( $msg)

Used within the class to return the $msg along with the output of mysql_error ( ).

GETTING HELP

As of 2002-06-30, there is a bulletin board for phpMysqkConnection located at http://www.koivi.com/php/.

Version 1.5.9

Version 1.5.8

Version 1.5

TODO List