amirkhoshhal
Member
سلام . از دوستان ممنون می شم اگه چند تا از کلاس های ساده رو برای بررسی و یادگیری بذارند
. یک دنیا ممنون .

class quiz_MySQL_Database
{
// Database Connection ID --------
/**
* The Online Competition database connection ID
*
* @var Online_Competition_Connection_ID
*/
var $cid;
// MySQL Database Functions --------------------
var $functions = array('connect' => 'mysql_connect', 'pconnect' =>
'mysql_pconnect', 'select_db' => 'mysql_select_db', 'query' => 'mysql_query',
'query_unbuffered' => 'mysql_unbuffered_query', 'fetch_row' => 'mysql_fetch_row',
'fetch_array' => 'mysql_fetch_array', 'fetch_field' => 'mysql_fetch_field',
'free_result' => 'mysql_free_result', 'data_seek' => 'mysql_data_seek', 'error' =>
'mysql_error', 'errno' => 'mysql_errno', 'affected_rows' =>
'mysql_affected_rows', 'num_rows' => 'mysql_num_rows', 'num_fields' =>
'mysql_num_fields', 'field_name' => 'mysql_field_name', 'insert_id' =>
'mysql_insert_id', 'escape_string' => 'mysql_escape_string',
'real_escape_string' => 'mysql_real_escape_string', 'close' => 'mysql_close',
'client_encoding' => 'mysql_client_encoding', );
/**
* Constructor
*
* @param string Database host
* @param integer Database port
* @param string Database username
* @param string Database password
* @param string Name of the database
* @param integer Open a persistent connection to a MySQL server
* @param string Technical email address to report the errors
*/
// *****------- Define the MySQL Database -------*****
function quiz_MySQL_Database($host, $port, $user, $pswd, $dbname, $pconnect = 0,
$technicalemail = null)
{
// --- Set the variables ---
$this->server = $host;
$this->port = $port;
$this->user = $user;
$this->pswd = $pswd;
$this->pconnect = $pconnect;
$this->dbname = $dbname;
// --- Connect to the database ---
if ($pconnect == 0)
$this->cid = $this->functions['connect']($this->server, $this->user, $this->
pswd, $this->port);
else
$this->cid = $this->functions['pconnect']($this->server, $this->user, $this->
pswd, $this->port);
// --- Select database ---
if (!empty($this->dbname))
$this->functions['select_db']($this->dbname);
}
// *****------- MySQL Query -------*****
/**
* Executes an SQL query, using either the write connection
*
* @param string The text of the SQL query to be executed
*
* @return string
*/
function query($sql = null)
{
$this->row[$sql] = @$this->functions['fetch_array']($sql, $this->cid);
$action = @$this->functions['query']($sql, $this->cid);
return $action;
}
// *****------- MySQL Unbuffered Query -------*****
/**
* Executes an SQL unbuffered query, using either the write connection
*
* @param string The text of the SQL query to be executed
*
* @return string
*/
function unbuffered_query($sql = null)
{
$this->row[$sql] = @$this->functions['fetch_array']($sql, $this->cid);
$action = @$this->functions['query_unbuffered']($sql, $this->cid);
return $action;
}
// *****------- MySQL Fetch Row -------*****
/**
* Fetches a row from a query result and returns the values from that row as an array with numeric keys
*
* @param string The query result ID we are dealing with
*
* @return array
*/
function fetch_row($sql = 0)
{
if ($sql) {
$this->row[$sql] = @$this->functions['fetch_array']($sql);
$action = $this->row[$sql];
return $action;
} else {
return false;
}
}
// *****------- MySQL Fetch Field -------*****
/**
* Fetches a row information from a query result and returns the values from that row as an array
*
* @param string The query result ID we are dealing with
*
* @return array
*/
function fetch_field($sql = 0)
{
$this->row[$sql] = @$this->functions['mysql_fetch_field']($sql, $this->cid);
$action = @$this->functions['query']($sql, $this->cid);
return $action;
}
// *****------- MySQL Free Result -------*****
/**
* Frees all memory associated with the specified query result
*
* @param string The query result ID we are dealing with
*
* @return boolean
*/
function free_result($sql = 0)
{
$action = @$this->functions['free_result']($sql);
return $action;
}
// *****------- MySQL Data Seek -------*****
/**
* Moves the internal result pointer within a query result set
*
* @param string The query result ID we are dealing with
* @param integer The position to which to move the pointer (first position is 0)
*
* @return boolean
*/
function data_seek($sql = 0, $row_num)
{
$action = @$this->functions['data_seek']($sql, $row_num);
return $action;
}
// *****------- MySQL Error -------*****
/**
* Retrieve the error message occured on connected database
*
* @return string
*/
function error()
{
$action = @$this->functions['error']($this->cid);
return $action;
}
// *****------- MySQL Errno -------*****
/**
* Retrieve the error no occured on connected database
*
* @return integer
*/
function errno()
{
$action = @$this->functions['errno']($this->cid);
return $action;
}
// *****------- MySQL Affected Rows -------*****
/**
* Retuns the number of rows affected by the most recent insert/replace/update query
*
* @return integer
*/
function affected_rows()
{
$action = @$this->functions['affected_rows']($this->cid);
return ($action);
}
// *****------- MySQL Num Rows -------*****
/**
* Returns the number of rows contained within a query result set
*
* @param string The query result ID we are dealing with
*
* @return integer
*/
function num_rows($sql = 0)
{
if ($sql) {
$action = @$this->functions['num_rows']($sql);
return $action;
} else {
return false;
}
}
// *****------- MySQL Num Fields -------*****
/**
* Returns the number of fields contained within a query result set
*
* @param string The query result ID we are dealing with
*
* @return integer
*/
function num_fields($sql = 0)
{
if ($sql) {
$action = @$this->functions['num_fields']($sql);
return $action;
} else {
return false;
}
}
// *****------- MySQL Field Name -------*****
/**
* Returns the name of a field from within a query result set
*
* @param string The query result ID we are dealing with
* @param integer The index position of the field
*
* @return string
*/
function field_name($sql = 0, $findex = 0)
{
if ($sql) {
$action = @$this->functions['field_name']($sql, $findex);
return $action;
} else {
return false;
}
}
// *****------- MySQL Insert ID -------*****
/**
* Returns the ID of the item just inserted into an auto-increment field
*
* @return integer
*/
function insert_id()
{
$action = @$this->functions['insert_id']($this->cid);
return $action;
}
// *****------- MySQL Escape String -------*****
/**
* Escapes a string to make it safe to be inserted into an SQL query
*
* @param string The string to be escaped
*
* @return string
*/
function escape_string($str = null)
{
if ($str) {
$action = @$this->functions['escape_string']($str);
return $action;
} else {
return false;
}
}
/**
* Escapes real a string to make it safe to be inserted into an SQL query
*
* @param string The string to be escaped
*
* @return string
*/
function real_escape_string($str = null)
{
if ($str) {
$action = @$this->functions['real_escape_string']($str, $this->cid);
return $action;
} else {
return false;
}
}
// *****------- MySQL Client Encoding -------*****
/**
* Returns the name of the character set
*
* @return string
*/
function client_encoding()
{
$action = @$this->functions['client_encoding']($this->cid);
return ($action);
}
// *****------- Close The Database -------*****
/**
* Closes the connection to the database server
*
* @return boolean
*/
function close()
{
if ($action = @$this->functions['close']($this->cid))
return $action;
else
return false;
}
}
من کارداني کامپيوتر خوندم ولي تو دانشگاه چيزي به نام PHP نداشتيمسلام . ممنون . ببخشید شما رشتتون چیه که PHP خوندید ؟
من دانشجوی ترم 1 کامپیوتر کاردانی هستم ولی PHP نخوندم .![]()