- This topic is empty.
-
AuthorPosts
-
February 6, 2010 at 7:04 am #27894AnthoniParticipant
I have create a simple Class for connecting, and sending queries to your MySQL database through php. There are already a set of functions for creating a connection to a MySQL Database and sending Queries of course, this just makes it a bit easier. Below is a list of functions for the class, and an example script from one of my web applications.
*Note: PHP file below.
Changelist:
[Version 1.3]
[Added] SelectDatabase( $db)
[Added] TableCreate( $name, $column_array )
[Added] TableInsert( $name, $column_array, $values_array)Class Variables:
$host – This host name for the SQL Connection, Defaults to localhost.
$database – This is the name of the Database that will be accessed.
$username – This is the username for the user accessing the database.
$password – This is the password for the user.
$connection – This is the variable when the SQL connection is stored.
$silent – This Determines if the class will echo debug information for it’s functions.Functions:
IsSilent( $bool ) – This function sets the silent variable.
Status( $message ) – This is a mainly internal function to display status messages. Only works if $silent is set to false.
SetHost( $hostname ) – This will set the $host variable.
SetDatabase( $db ) – Sets the Database to be used.
SetUsername( $user ) – Sets the Username that will be used.
SetPassword( $pass ) – Sets the Password that will be used.
Connect() – Connects to the SQL Server with provided information.
Query() – Attempts to run a Query on the SQL Server, returns the result.
Close() – Closes the Current SQL Connection.
SelectDatabase( $db ) – Sets the Database, Variable and Selects it.
TableCreate( $name, $column_array ) – Creates a New Table.
TableInsert( $name, $column_array, $values_array) – Inserts Data into a Table.
TODO: SelectTable( $name ) – Selects a Table.
TODO: DropTable( $name ) – Drops a Table.
Example:
Code:SetDatabase( ‘yourdatabasenamehere’ );
$sql->SetUsername( ‘yourusernamehere’ );
$sql->SetPassword( ‘yourpasswordhere’ );$sql->IsSilent( false );
$sql->Connect();
$columnsA = Array( ‘id INT PRIMARY KEY AUTO_INCREMENT’ , ‘username VARCHAR(255)’ , ‘password VARCHAR(255)’ );
$columnsB = Array( ‘username’ , ‘password’ );
$valuesA = Array( ‘”Anthoni”‘ , ‘”TestPass”‘ );
$valuesB = Array( ‘”Mark”‘ , ‘”Whalberg”‘ );$sql->TableCreate( ‘tbl_test’, $columnsA );
$sql->TableInsert( ‘tbl_test’, $columnsB, $valuesA );
$sql->TableInsert( ‘tbl_test’, $columnsB, $valuesb );$sql->Close();
?>
Example Script on PasteAll: http://www.pasteall.org/10824/php
Get the Script Here: http://www.pasteall.org/10823/php
If you have any comments, questions, or bugs please post them below. Thanks!
February 6, 2010 at 9:21 am #70554AnthoniParticipantNo Problem. This is the first time I have actually though about releasing my scripts. Maybe I will start releasing more. :)
June 15, 2010 at 6:15 pm #77554eXoMemberLooks very usefull :), thanks for sharing!
July 7, 2010 at 9:59 am #79337MakeshiftMemberwow, took me a little to figure out this that and the other, but this.. it’s simply amazing. I love it.. thank you very much.
-
AuthorPosts
- The forum ‘Other’ is closed to new topics and replies.