Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other [Free Resource] Php MySQL Class 1.3

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #27894
    Anthoni
    Participant

    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!

    #70554
    Anthoni
    Participant

    No Problem. This is the first time I have actually though about releasing my scripts. Maybe I will start releasing more. :)

    #77554
    eXo
    Member

    Looks very usefull :), thanks for sharing!

    #79337
    Makeshift
    Member

    wow, 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.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘Other’ is closed to new topics and replies.