- Impact
- 73
Just writing code tonight and as always - used my connection class for connecting to mysql. Thought about it, and even for those who aren't that great with php/mysql, makes connecting to a database easier (and less repetitive - something classes/functions are great for).
So, I'm releasing it as "SMyCC - Simple MySQL Connection Class" to the Namepros Community, and then to the public.
To run the MySQL Connection, you will have to call a new instance of the class and tell it what function to run:
To Run a specific Query on the database:
To Close the MySQL Connection, Run the End function of the class instance:
If you read through the class code, you will have noticed that there is a reference to "database.inc.php". This is a file with the necessary connection data to access the database. It is available inside the download below.
The entire package is available for download on my (project) website:
http://www.stscac.com/dev/smycc/
Hope you like it.
-Steve
So, I'm releasing it as "SMyCC - Simple MySQL Connection Class" to the Namepros Community, and then to the public.
PHP:
<?
/*
SMyCC [Pronounced "smEEk"]
(Simple MySQL Connection Class)
ยฉ 2005-2006 Steve Castle
http://www.stscac.com
*/
class mysql
{
var $server;
var $conn_username;
var $conn_password;
var $database_name;
var $connection;
var $select;
var $query;
function connect()
{
require "database.inc.php";
$connection = mysql_connect($server,$conn_username,$conn_password);
$select = mysql_select_db($database_name,$connection);
}
function query($query)
{
$result = mysql_query($query);
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
}
function end()
{
mysql_free_result($connection);
}
}
PHP:
$mysql = new mysql();
$mysql->connect();
PHP:
// The Query here is a sample for this instance
$mysql->query("SELECT * FROM table WHERE something='something_else'");
PHP:
//You Must have run the $mysql->query to be able to use the $mysql->end function
$mysql->end();
If you read through the class code, you will have noticed that there is a reference to "database.inc.php". This is a file with the necessary connection data to access the database. It is available inside the download below.
The entire package is available for download on my (project) website:
http://www.stscac.com/dev/smycc/
Hope you like it.
-Steve







