MySQL Database Connection
Class manual
Contents
Introduction
How do I use MySQL Database Connection Class?
version
0.8
version 0.7
version 0.6
version 0.5
version 0.4
version 0.3
version 0.2
version 0.1
ChangeLog
Introduction
MySQL Database Connection Class
is database connection and program debugging class of mysql components
designed to provide database connection and data retrival more easy.
MySQL Database Connection Class
v0.1 was introduced by Alangor Program Studio in 2002 as a utility offering
a limited set of mysql database connection and data retrival functionality.
With the releases of later
versions, which is only accessible in the presence of a paid-for Alangor
Program Studio publishing license.
How
do I use MySQL Database Connection Class?
Version
0.8
Predefine to use some helpful
function
Create class object will predefine
the function
MySQL live connection. Must
used with close mysql database connection
|
$sql->sql_life_connect=false;
|
Report all mysql and php errors
setting
Manual set error_porting of
php.ini which PHP errors are reported
|
$sql->set_error_reporting=1;
|
Open mysql database connection
Close mysql database connection
Checking mysql database connection
can connect or not
|
$sql->check_connection();
|
Send mysql query
|
$result=$sql->sql_query("select
* from table");
|
Send mysql query and auto connection
and close database
|
$result=$sql->sql_process("select
field1,field2 from table");
|
Get number of rows in mysql
query result
|
$sql_record_count=$sql->sql_num_rows($result);
|
Get a mysql query result row
as an enumerated array
|
$row=$sql->sql_fetch_row($result);
echo $row[0];
// field1;
echo $row[1];
// field2;
|
Fetch a mysql query result
row as an associative array, a numeric array, or both
|
while($row=$sql->sql_fetch_array($result)){
echo $row["field1"];
// field1;
echo $row["field2"];
// field2;
}
|
Get number of fields in mysql
query result
|
$sql_field_count=$sql->sql_num_fields($result);
|
Get all field specification
of the table in mysql query result with the table name
|
$field_result=$sql->sql_table_fields("tablename");
|
Move internal mysql result
pointer of the mysql result associated with the specified result identifier.
|
$sql->sql_reset($result,1);
|
Move internal mysql result
pointer of the mysql result associated with the 0 identifier.
|
$sql->sql_reset($result);
|
v0.8 Example 1
Using mysql automatic connection
method and the class function example.
|
<?
/**
* predefine to use some helpful function
* $show_error="version"; // database.class.php version
* $show_error="php.ini"; // server current php.ini setting
* $show_error="true"; // mysql and php error
* $show_error=""; // define no use helpful function
*/
$show_error="version";
// include the class file
include_once "database.class.php";
// create the class object and predefine
the function
$sql=new
sql_class;
/**
* report all mysql and php errors setting
* $sql->show_error=true; // show error report
* $sql->show_error=false; // not show error report
*/
$sql->show_error=true;
/**
* Set which PHP errors are reported.
*
* // Using php.ini default error reporting
* $set_error_reporting="";
*
* // Turn off all error reporting
* $set_error_reporting="0";
*
* // Report all PHP errors
* // error_reporting(E_ALL);
* $set_error_reporting="1";
*
* // Report errors only
* // error_reporting(E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR);
* $set_error_reporting="2";
*
* // Report simple running errors
* // error_reporting(E_ERROR|E_WARNING|E_PARSE);
* $set_error_reporting="3";
*
* // Reporting E_NOTICE can be good too (to report uninitialized
* // variables or catch variable name misspellings ...)
* // error_reporting(E_ERROR|E_WARNING|E_PARSE|E_NOTICE);
* $set_error_reporting="4";
*
* // Report all errors except E_NOTICE
* // This is the default value set in php.ini
* // error_reporting(E_ALL^E_NOTICE);
* $set_error_reporting="5";
*/
$sql->set_error_reporting=1;
// define mysql information
$sql->sql_host="localhost";
$sql->sql_db="";
$sql->sql_user="";
$sql->sql_pass="";
// check mysql database connection
$sql->check_connection();
// send mysql query
$result=$sql->sql_query("select
field1,field2,field3 from table");
// get number of rows in mysql query
result
$sql_record_count=$sql->sql_num_rows($result);
// get number of fields in mysql query
result
$sql_field_count=$sql->sql_num_fields($result);
// get all field specification of the
table in mysql query result with the table name
$field_array=$sql->sql_table_fields("tablename");
for($i=0;$i<count($field_array);$i++){
echo $field_array[$i]["Field"];
echo $field_array[$i]["Type"];
echo $field_array[$i]["Null"];
echo $field_array[$i]["Key"];
echo $field_array[$i]["Default"];
echo $field_array[$i]["Extra"];
}
// move internal mysql result pointer
of the mysql result associated with the specified result identifier
$sql->sql_data_seek($result,1);
// move internal mysql result pointer
of the mysql result associated with the 0 identifier
$sql->sql_reset($result);
?>
|
v0.8 Example 2
Using mysql live connection.
|
<?
// include the class file
include_once "database.class.php";
// create the class object and predefine
the function
$sql=new
sql_class;
// mysql live connection
$sql->sql_life_connect=true;
// define mysql information
$sql->sql_host="localhost";
$sql->sql_db="";
$sql->sql_user="";
$sql->sql_pass="";
// send mysql query
$result=$sql->sql_query("select
field1,field2,field3 from table");
$myownresult=mysql_query("select
* from table");
$myownresult2=mysql_query("select
* from table2");
// close database connection
$sql->closedb();
?>
|
v0.8 Example 3
Just set the $show_error="true"
to dsiplay mysql and php error. No need $sql->show_error=true;.
|
<?
/**
* predefine to use some helpful function
* $show_error="version"; // database.class.php
version
* $show_error="php.ini"; // server current
php.ini setting
* $show_error="true"; //
mysql and php error
* $show_error=""; //
define no use helpful function
*/
$show_error="true";
// include the class file
include_once "database.class.php";
// create the class object and predefine
the function
$sql=new
sql_class;
/**
* Set which PHP errors are reported.
*
* // Using php.ini default error reporting
* $set_error_reporting="";
*
* // Turn off all error reporting
* $set_error_reporting="0";
*
* // Report all PHP errors
* // error_reporting(E_ALL);
* $set_error_reporting="1";
*
* // Report errors only
* // error_reporting(E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR);
* $set_error_reporting="2";
*
* // Report simple running errors
* // error_reporting(E_ERROR|E_WARNING|E_PARSE);
* $set_error_reporting="3";
*
* // Reporting E_NOTICE can be good too (to report uninitialized
* // variables or catch variable name misspellings ...)
* // error_reporting(E_ERROR|E_WARNING|E_PARSE|E_NOTICE);
* $set_error_reporting="4";
*
* // Report all errors except E_NOTICE
* // This is the default value set in php.ini
* // error_reporting(E_ALL^E_NOTICE);
* $set_error_reporting="5";
*/
$sql->set_error_reporting=1;
// define mysql information
$sql->sql_host="localhost";
$sql->sql_db="";
$sql->sql_user="";
$sql->sql_pass="";
// check mysql database connection
$sql->check_connection();
// send mysql query
$result=$sql->sql_query("select
field1,field2,field3 from table");
// get number of rows in mysql query
result
$sql_record_count=$sql->sql_num_rows($result);
// get number of fields in mysql query
result
$sql_field_count=$sql->sql_num_fields($result);
// get all field specification of the
table in mysql query result with the table name
$field_array=$sql->sql_table_fields("tablename");
for($i=0;$i<count($field_array);$i++){
echo $field_array[$i]["Field"];
echo $field_array[$i]["Type"];
echo $field_array[$i]["Null"];
echo $field_array[$i]["Key"];
echo $field_array[$i]["Default"];
echo $field_array[$i]["Extra"];
}
// move internal mysql result pointer
of the mysql result associated with the specified result identifier
$sql->sql_data_seek($result,1);
// move internal mysql result pointer
of the mysql result associated with the 0 identifier
$sql->sql_reset($result);
?>
|
Version
0.7
Predefine to use some helpful
function
Create class object will predefine
the function
MySQL live connection. Must
used with close mysql database connection
|
$sql->sql_life_connect=false;
|
Report all mysql and php errors
setting
Manual set error_porting of
php.ini which PHP errors are reported
|
$sql->set_error_reporting=1;
|
Open mysql database connection
Close mysql database connection
Checking mysql database connection
can connect or not
|
$sql->check_connection();
|
Send mysql query
|
$result=$sql->sql_query("select
* from table");
|
Send mysql query and auto connection
and close database
|
$result=$sql->sql_process("select
field1,field2 from table");
|
Get number of rows in mysql
query result
|
$sql_record_count=$sql->sql_num_rows($result);
|
Get a mysql query result row
as an enumerated array
|
$row=$sql->sql_fetch_row($result);
echo $row[0];
// field1;
echo $row[1];
// field2;
|
Fetch a mysql query result
row as an associative array, a numeric array, or both
|
while($row=$sql->sql_fetch_array($result)){
echo $row["field1"];
// field1;
echo $row["field2"];
// field2;
}
|
Get number of fields in mysql
query result
|
$sql_field_count=$sql->sql_num_fields($result);
|
Get name of the table the
specified field is in mysql query result
|
$tablename=$sql->sql_field_table($result,"field1");
|
Get the name of the specified
field in mysql query result
|
$field1_name=$sql->sql_field_name($result,0);
$field3_name=$sql->sql_field_name($result,2);
|
Get all field specification
of the table in mysql query result with one of the field name
|
$field_result=$sql->sql_show_fields($result,"field1");
|
Move internal mysql result
pointer of the mysql result associated with the 0 identifier.
|
$sql->sql_reset($result);
|
v0.7 Example 1
Using mysql automatic connection
method and the class function example.
|
<?
/**
* predefine to use some helpful function
* $show_error="version"; // database.class.php
version
* $show_error="php.ini"; // server current
php.ini setting
* $show_error="true"; //
mysql and php error
* $show_error=""; //
define no use helpful function
*/
$show_error="version";
// include the class file
include_once "database.class.php";
// create the class object and predefine
the function
$sql=new
sql_class;
/**
* report all mysql and php errors setting
* $sql->show_error=true; // show error
report
* $sql->show_error=false; // not show
error report
*/
$sql->show_error=true;
/**
* Set which PHP errors are reported.
*
* // Using php.ini default error reporting
* $set_error_reporting="";
*
* // Turn off all error reporting
* $set_error_reporting="0";
*
* // Report all PHP errors
* // error_reporting(E_ALL);
* $set_error_reporting="1";
*
* // Report errors only
* // error_reporting(E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR);
* $set_error_reporting="2";
*
* // Report simple running errors
* // error_reporting(E_ERROR|E_WARNING|E_PARSE);
* $set_error_reporting="3";
*
* // Reporting E_NOTICE can be good too (to report uninitialized
* // variables or catch variable name misspellings ...)
* // error_reporting(E_ERROR|E_WARNING|E_PARSE|E_NOTICE);
* $set_error_reporting="4";
*
* // Report all errors except E_NOTICE
* // This is the default value set in php.ini
* // error_reporting(E_ALL^E_NOTICE);
* $set_error_reporting="5";
*/
$sql->set_error_reporting=1;
// define mysql information
$sql->sql_host="localhost";
$sql->sql_db="";
$sql->sql_user="";
$sql->sql_pass="";
// check mysql database connection
$sql->check_connection();
// send mysql query
$result=$sql->sql_query("select
field1,field2,field3 from table");
// get number of rows in mysql query
result
$sql_record_count=$sql->sql_num_rows($result);
// get number of fields in mysql query
result
$sql_field_count=$sql->sql_num_fields($result);
// get name of the table the specified
field is in mysql query result
$tablename=$sql->sql_field_table($result,"field1");
// get the name of the specified field
in mysql query result
$field1_name=$sql->sql_field_name($result,0);
$field3_name=$sql->sql_field_name($result,2);
// get all field specification of the
table in mysql query result with one of the field name
$field_result=$sql->sql_show_fields($result,"field1");
// fetch a result row as an associative
array, a numeric array, or both
while($sql_row=$this->sql_fetch_array($field_result)){
echo $sql_row["Field"];
echo $sql_row["Type"];
echo $sql_row["Null"];
echo $sql_row["Key"];
echo $sql_row["Default"];
echo $sql_row["Extra"];
}
// move internal mysql result pointer
of the mysql result associated with the 0 identifier
$sql->sql_reset($result);
?>
|
v0.7 Example 2
Using mysql live connection.
|
<?
// include the class file
include_once "database.class.php";
// create the class object and predefine
the function
$sql=new
sql_class;
// mysql live connection
$sql->sql_life_connect=true;
// define mysql information
$sql->sql_host="localhost";
$sql->sql_db="";
$sql->sql_user="";
$sql->sql_pass="";
// send mysql query
$result=$sql->sql_query("select
field1,field2,field3 from table");
$myownresult=mysql_query("select
* from table");
$myownresult2=mysql_query("select
* from table2");
// close database connection
$sql->closedb();
?>
|
v0.7 Example 3
Just set the $show_error="true"
to dsiplay mysql and php error. No need $sql->show_error=true;.
|
<?
/**
* predefine to use some helpful function
* $show_error="version"; // database.class.php
version
* $show_error="php.ini"; // server current
php.ini setting
* $show_error="true"; //
mysql and php error
* $show_error=""; //
define no use helpful function
*/
$show_error="true";
// include the class file
include_once "database.class.php";
// create the class object and predefine
the function
$sql=new
sql_class;
/**
* Set which PHP errors are reported.
*
* // Using php.ini default error reporting
* $set_error_reporting="";
*
* // Turn off all error reporting
* $set_error_reporting="0";
*
* // Report all PHP errors
* // error_reporting(E_ALL);
* $set_error_reporting="1";
*
* // Report errors only
* // error_reporting(E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR);
* $set_error_reporting="2";
*
* // Report simple running errors
* // error_reporting(E_ERROR|E_WARNING|E_PARSE);
* $set_error_reporting="3";
*
* // Reporting E_NOTICE can be good too (to report uninitialized
* // variables or catch variable name misspellings ...)
* // error_reporting(E_ERROR|E_WARNING|E_PARSE|E_NOTICE);
* $set_error_reporting="4";
*
* // Report all errors except E_NOTICE
* // This is the default value set in php.ini
* // error_reporting(E_ALL^E_NOTICE);
* $set_error_reporting="5";
*/
$sql->set_error_reporting=1;
// define mysql information
$sql->sql_host="localhost";
$sql->sql_db="";
$sql->sql_user="";
$sql->sql_pass="";
// check mysql database connection
$sql->check_connection();
// send mysql query
$result=$sql->sql_query("select
field1,field2,field3 from table");
// get number of rows in mysql query
result
$sql_record_count=$sql->sql_num_rows($result);
// get number of fields in mysql query
result
$sql_field_count=$sql->sql_num_fields($result);
// get name of the table the specified
field is in mysql query result
$tablename=$sql->sql_field_table($result,"field1");
// get the name of the specified field
in mysql query result
$field1_name=$sql->sql_field_name($result,0);
$field3_name=$sql->sql_field_name($result,2);
// get all field specification of the
table in mysql query result with one of the field name
$field_result=$sql->sql_show_fields($result,"field1");
// fetch a result row as an associative
array, a numeric array, or both
while($sql_row=$this->sql_fetch_array($field_result)){
echo $sql_row["Field"];
echo $sql_row["Type"];
echo $sql_row["Null"];
echo $sql_row["Key"];
echo $sql_row["Default"];
echo $sql_row["Extra"];
}
// move internal mysql result pointer
of the mysql result associated with the 0 identifier
$sql->sql_reset($result);
?>
|
Version
0.6
Predefine to use some helpful
function
Create class object will predefine
the function
MySQL live connection. Must
used with close mysql database connection
|
$sql->sql_life_connect=false;
|
Report all mysql and php errors
setting
Manual set error_porting of
php.ini which PHP errors are reported
|
$sql->set_error_reporting=1;
|
Open mysql database connection
Close mysql database connection
Checking mysql database connection
can connect or not
|
$sql->check_connection();
|
Send mysql query
|
$result=$sql->sql_query("select
* from table");
|
Send mysql query and auto connection
and close database
|
$result=$sql->sql_process("select
field1,field2 from table");
|
Get number of rows in mysql
query result
|
$sql_record_count=$sql->sql_num_rows($result);
|
Get a mysql query result row
as an enumerated array
|
$row=$sql->sql_fetch_row($result);
echo $row[0];
// field1;
echo $row[1];
// field2;
|
Fetch a mysql query result
row as an associative array, a numeric array, or both
|
while($row=$sql->sql_fetch_array($result)){
echo $row["field1"];
// field1;
echo $row["field2"];
// field2;
}
|
Get number of fields in mysql
query result
|
$sql_field_count=$sql->sql_num_fields($result);
|
Get name of the table the
specified field is in mysql query result
|
$tablename=$sql->sql_field_table($result,"field1");
|
Get the name of the specified
field in mysql query result
|
$field1_name=$sql->sql_field_name($result,0);
$field3_name=$sql->sql_field_name($result,2);
|
Get all field specification
of the table in mysql query result with one of the field name
|
$field_result=$sql->sql_show_fields($result,"field1");
|
Move internal mysql result
pointer of the mysql result associated with the 0 identifier.
|
$sql->sql_reset($result);
|
v0.6 Example 1
Using mysql automatic connection
method and the class function example.
|
<?
/**
* predefine to use some helpful function
* $show_error="version"; // database.class.php
version
* $show_error="php.ini"; // server current
php.ini setting
* $show_error="true"; //
mysql and php error
* $show_error=""; //
define no use helpful function
*/
$show_error="version";
// include the class file
include_once "database.class.php";
// create the class object and predefine
the function
$sql=new
sql_class;
/**
* report all mysql and php errors setting
* $sql->show_error=true; // show error
report
* $sql->show_error=false; // not show
error report
*/
$sql->show_error=true;
/**
* Set which PHP errors are reported.
*
* // Using php.ini default error reporting
* $set_error_reporting="";
*
* // Turn off all error reporting
* $set_error_reporting="0";
*
* // Report all PHP errors
* // error_reporting(E_ALL);
* $set_error_reporting="1";
*
* // Report errors only
* // error_reporting(E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR);
* $set_error_reporting="2";
*
* // Report simple running errors
* // error_reporting(E_ERROR|E_WARNING|E_PARSE);
* $set_error_reporting="3";
*
* // Reporting E_NOTICE can be good too (to report uninitialized
* // variables or catch variable name misspellings ...)
* // error_reporting(E_ERROR|E_WARNING|E_PARSE|E_NOTICE);
* $set_error_reporting="4";
*
* // Report all errors except E_NOTICE
* // This is the default value set in php.ini
* // error_reporting(E_ALL^E_NOTICE);
* $set_error_reporting="5";
*/
$sql->set_error_reporting=1;
// define mysql information
$sql->sql_host="localhost";
$sql->sql_db="";
$sql->sql_user="";
$sql->sql_pass="";
// check mysql database connection
$sql->check_connection();
// send mysql query
$result=$sql->sql_query("select
field1,field2,field3 from table");
// get number of rows in mysql query
result
$sql_record_count=$sql->sql_num_rows($result);
// get number of fields in mysql query
result
$sql_field_count=$sql->sql_num_fields($result);
// get name of the table the specified
field is in mysql query result
$tablename=$sql->sql_field_table($result,"field1");
// get the name of the specified field
in mysql query result
$field1_name=$sql->sql_field_name($result,0);
$field3_name=$sql->sql_field_name($result,2);
// get all field specification of the
table in mysql query result with one of the field name
$field_result=$sql->sql_show_fields($result,"field1");
// fetch a result row as an associative
array, a numeric array, or both
while($sql_row=$this->sql_fetch_array($field_result)){
echo $sql_row["Field"];
echo $sql_row["Type"];
echo $sql_row["Null"];
echo $sql_row["Key"];
echo $sql_row["Default"];
echo $sql_row["Extra"];
}
// move internal mysql result pointer
of the mysql result associated with the 0 identifier
$sql->sql_reset($result);
?>
|
v0.6 Example 2
Using mysql live connection.
|
<?
// include the class file
include_once "database.class.php";
// create the class object and predefine
the function
$sql=new
sql_class;
// mysql live connection
$sql->sql_life_connect=true;
// define mysql information
$sql->sql_host="localhost";
$sql->sql_db="";
$sql->sql_user="";
$sql->sql_pass="";
// send mysql query
$result=$sql->sql_query("select
field1,field2,field3 from table");
$myownresult=mysql_query("select
* from table");
$myownresult2=mysql_query("select
* from table2");
// close database connection
$sql->closedb();
?>
|
Version
0.5
Predefine to use some helpful
function
Create class object will predefine
the function
Report all mysql and php errors
setting
Manual set error_porting of
php.ini which PHP errors are reported
|
$sql->set_error_reporting=1;
|
Open database
Close database
Checking mysql database connection
can connect or not
|
$sql->check_connection();
|
Send mysql query
|
$result=$sql->sql_query("select
* from table");
|
Send mysql query and auto connection
and close database
|
$result=$sql->sql_process("select
field1,field2 from table");
|
Get number of rows in mysql
query result
|
$sql_record_count=$sql->sql_num_rows($result);
|
Get a mysql query result row
as an enumerated array
|
$row=$sql->sql_fetch_row($result);
echo $row[0];
// field1;
echo $row[1];
// field2;
|
Fetch a mysql query result
row as an associative array, a numeric array, or both
|
while($row=$sql->sql_fetch_array($result)){
echo $row["field1"];
// field1;
echo $row["field2"];
// field2;
}
|
Get number of fields in mysql
query result
|
$sql_field_count=$sql->sql_num_fields($result);
|
Get name of the table the
specified field is in mysql query result
|
$tablename=$sql->sql_field_table($result,"field1");
|
Get the name of the specified
field in mysql query result
|
$field1_name=$sql->sql_field_name($result,0);
$field3_name=$sql->sql_field_name($result,2);
|
Get all field specification
of the table in mysql query result with one of the field name
|
$field_result=$sql->sql_show_fields($result,"field1");
|
Move internal mysql result
pointer of the mysql result associated with the 0 identifier.
|
$sql->sql_reset($result);
|
v0.5 Example
|
<?
/**
* predefine to use some helpful function
* $show_error="version"; // database.class.php
version
* $show_error="php.ini"; // server current
php.ini setting
* $show_error="true"; //
mysql and php error
* $show_error=""; //
define no use helpful function
*/
$show_error="version";
// include the class file
include_once "database.class.php";
// create the class object and predefine
the function
$sql=new
sql_class;
/**
* report all mysql and php errors setting
* $sql->show_error=true; // show error
report
* $sql->show_error=false; // not show
error report
*/
$sql->show_error=true;
/**
* Set which PHP errors are reported.
*
* // Using php.ini default error reporting
* $set_error_reporting="";
*
* // Turn off all error reporting
* $set_error_reporting="0";
*
* // Report all PHP errors
* // error_reporting(E_ALL);
* $set_error_reporting="1";
*
* // Report errors only
* // error_reporting(E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR);
* $set_error_reporting="2";
*
* // Report simple running errors
* // error_reporting(E_ERROR|E_WARNING|E_PARSE);
* $set_error_reporting="3";
*
* // Reporting E_NOTICE can be good too (to report uninitialized
* // variables or catch variable name misspellings ...)
* // error_reporting(E_ERROR|E_WARNING|E_PARSE|E_NOTICE);
* $set_error_reporting="4";
*
* // Report all errors except E_NOTICE
* // This is the default value set in php.ini
* // error_reporting(E_ALL^E_NOTICE);
* $set_error_reporting="5";
*/
$sql->set_error_reporting=1;
// define mysql information
$sql->sql_host="localhost";
$sql->sql_db="";
$sql->sql_user="";
$sql->sql_pass="";
// check mysql database connection
$sql->check_connection();
// send mysql query
$result=$sql->sql_query("select
field1,field2,field3 from table");
// get number of rows in mysql query
result
$sql_record_count=$sql->sql_num_rows($result);
// get number of fields in mysql query
result
$sql_field_count=$sql->sql_num_fields($result);
// get name of the table the specified
field is in mysql query result
$tablename=$sql->sql_field_table($result,"field1");
// get the name of the specified field
in mysql query result
$field1_name=$sql->sql_field_name($result,0);
$field3_name=$sql->sql_field_name($result,2);
// get all field specification of the
table in mysql query result with one of the field name
$field_result=$sql->sql_show_fields($result,"field1");
// fetch a result row as an associative
array, a numeric array, or both
while($sql_row=$this->sql_fetch_array($field_result)){
echo $sql_row["Field"];
echo $sql_row["Type"];
echo $sql_row["Null"];
echo $sql_row["Key"];
echo $sql_row["Default"];
echo $sql_row["Extra"];
}
// move internal mysql result pointer
of the mysql result associated with the 0 identifier
$sql->sql_reset($result);
?>
|
Version
0.4
Predefine to use some helpful
function
Create class object will predefine
the function
Report all mysql and php errors
setting
Show mysql error or use some
function
Manual set error_porting of
php.ini which PHP errors are reported
|
$sql->set_error_reporting=1;
|
Open database
Close database
Checking mysql database connection
can connect or not
|
$sql->check_connection();
|
Send mysql query
|
$result=$sql->sql_query("select
* from table");
|
Send mysql query and auto connection
and close database
|
$result=$sql->sql_process("select
field1,field2 from table");
|
Get number of rows in mysql
query result
|
$sql_record_count=$sql->sql_num_rows($result);
|
Get a mysql query result row
as an enumerated array
|
$row=$sql->sql_fetch_row($result);
echo $row[0];
// field1;
echo $row[1];
// field2;
|
Fetch a mysql query result
row as an associative array, a numeric array, or both
|
while($row=$sql->sql_fetch_array($result)){
echo $row["field1"];
// field1;
echo $row["field2"];
// field2;
}
|
Get number of fields in mysql
query result
|
$sql_field_count=$sql->sql_num_fields($result);
|
Get name of the table the
specified field is in mysql query result
|
$tablename=$sql->sql_field_table($result,"field1");
|
Get the name of the specified
field in mysql query result
|
$field1_name=$sql->sql_field_name($result,0);
$field3_name=$sql->sql_field_name($result,2);
|
Get all field specification
of the table in mysql query result with one of the field name
|
$field_result=$sql->sql_show_fields($result,"field1");
|
Move internal mysql result
pointer of the mysql result associated with the 0 identifier.
|
$sql->sql_reset($result);
|
v0.4Example
|
<?
/**
* predefine to use some helpful function
* $show_error="version"; // database.class.php
version
* $show_error="php.ini"; // server current
php.ini setting
* $show_error="true"; //
mysql and php error
* $show_error=""; //
define no use helpful function
*/
$show_error="version";
// include the class file
include_once "database.class.php";
// create the class object and predefine
the function
$sql=new
sql_class;
/**
* report all mysql and php errors setting
* $sql->show_error=true; // show error
report
* $sql->show_error=false; // not show
error report
*/
$sql->show_error=true;
/**
* show mysql error or use some function
* function 1: show mysql error when $sql->show_error=true or
$show_error=true
* function 2: show server current php.ini setting
* function 3: show database.class.php version
*/
$sql->show_sql_error();
/**
* Set which PHP errors are reported.
*
* // Using php.ini default error reporting
* $set_error_reporting="";
*
* // Turn off all error reporting
* $set_error_reporting="0";
*
* // Report all PHP errors
* // error_reporting(E_ALL);
* $set_error_reporting="1";
*
* // Report errors only
* // error_reporting(E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR);
* $set_error_reporting="2";
*
* // Report simple running errors
* // error_reporting(E_ERROR|E_WARNING|E_PARSE);
* $set_error_reporting="3";
*
* // Reporting E_NOTICE can be good too (to report uninitialized
* // variables or catch variable name misspellings ...)
* // error_reporting(E_ERROR|E_WARNING|E_PARSE|E_NOTICE);
* $set_error_reporting="4";
*
* // Report all errors except E_NOTICE
* // This is the default value set in php.ini
* // error_reporting(E_ALL^E_NOTICE);
* $set_error_reporting="5";
*/
$sql->set_error_reporting=1;
// define mysql information
$sql->sql_host="localhost";
$sql->sql_db="";
$sql->sql_user="";
$sql->sql_pass="";
// check mysql database connection
$sql->check_connection();
// send mysql query
$result=$sql->sql_query("select
field1,field2,field3 from table");
// get number of rows in mysql query
result
$sql_record_count=$sql->sql_num_rows($result);
// get number of fields in mysql query
result
$sql_field_count=$sql->sql_num_fields($result);
// get name of the table the specified
field is in mysql query result
$tablename=$sql->sql_field_table($result,"field1");
// get the name of the specified field
in mysql query result
$field1_name=$sql->sql_field_name($result,0);
$field3_name=$sql->sql_field_name($result,2);
// get all field specification of the
table in mysql query result with one of the field name
$field_result=$sql->sql_show_fields($result,"field1");
// fetch a result row as an associative
array, a numeric array, or both
while($sql_row=$this->sql_fetch_array($field_result)){
echo $sql_row["Field"];
echo $sql_row["Type"];
echo $sql_row["Null"];
echo $sql_row["Key"];
echo $sql_row["Default"];
echo $sql_row["Extra"];
}
// move internal mysql result pointer
of the mysql result associated with the 0 identifier
$sql->sql_reset($result);
?>
|
Version
0.3
Open database
Close database
Checking mysql database connection
can connect or not
|
$sql->check_connection();
|
Send mysql query
|
$result=$sql->sql_query("select
* from table");
|
Send mysql query and auto connection
and close database
|
$result=$sql->sql_process("select
field1,field2 from table");
|
Get number of rows in mysql
query result
|
$sql_record_count=$sql->sql_num_rows($result);
|
Get a mysql query result row
as an enumerated array
|
$row=$sql->sql_fetch_row($result);
echo $row[0];
// field1;
echo $row[1];
// field2;
|
Fetch a mysql query result
row as an associative array, a numeric array, or both
|
while($row=$sql->sql_fetch_array($result)){
echo $row["field1"];
// field1;
echo $row["field2"];
// field2;
}
|
Get number of fields in mysql
query result
|
$sql_field_count=$sql->sql_num_fields($result);
|
Get name of the table the
specified field is in mysql query result
|
$tablename=$sql->sql_field_table($result,"field1");
|
Get the name of the specified
field in mysql query result
|
$field1_name=$sql->sql_field_name($result,0);
$field3_name=$sql->sql_field_name($result,2);
|
Get all field specification
of the table in mysql query result with one of the field name
|
$field_result=$sql->sql_show_fields($result,"field1");
|
Move internal mysql result
pointer of the mysql result associated with the 0 identifier.
|
$sql->sql_reset($result);
|
v0.3 Example
|
<?
// include the class file
include_once "database.class.php";
// create the class object
$sql=new
sql_class;
// define mysql information
$sql->sql_host="localhost";
$sql->sql_db="";
$sql->sql_user="";
$sql->sql_pass="";
// check mysql database connection
$sql->check_connection();
// send mysql query
$result=$sql->sql_query("select
field1,field2,field3 from table");
// get number of rows in mysql query
result
$sql_record_count=$sql->sql_num_rows($result);
// get number of fields in mysql query
result
$sql_field_count=$sql->sql_num_fields($result);
// get name of the table the specified
field is in mysql query result
$tablename=$sql->sql_field_table($result,"field1");
// get the name of the specified field
in mysql query result
$field1_name=$sql->sql_field_name($result,0);
$field3_name=$sql->sql_field_name($result,2);
// get all field specification of the
table in mysql query result with one of the field name
$field_result=$sql->sql_show_fields($result,"field1");
// fetch a result row as an associative
array, a numeric array, or both
while($sql_row=$this->sql_fetch_array($field_result)){
echo $sql_row["Field"];
echo $sql_row["Type"];
echo $sql_row["Null"];
echo $sql_row["Key"];
echo $sql_row["Default"];
echo $sql_row["Extra"];
}
// move internal mysql result pointer
of the mysql result associated with the 0 identifier
$sql->sql_reset($result);
// after sql_reset()
function. The mysql result can reuse again
while($sql_row=$this->sql_fetch_array($field_result)){
echo $sql_row["Field"];
echo $sql_row["Type"];
echo $sql_row["Null"];
echo $sql_row["Key"];
echo $sql_row["Default"];
echo $sql_row["Extra"];
}
?>
|
Version
0.2
Open database
Close database
Send mysql query
|
$result=$sql->sql_query("select
* from table");
|
Send mysql query and auto connection
and close database
|
$result=$sql->sql_process("select
field1,field2 from table");
|
Get number of rows in mysql
query result
|
$sql_record_count=$sql->sql_num_rows($result);
|
Get a mysql query result row
as an enumerated array
|
$row=$sql->sql_fetch_row($result);
echo $row[0];
// field1;
echo $row[1];
// field2;
|
Fetch a mysql query result
row as an associative array, a numeric array, or both
|
while($row=$sql->sql_fetch_array($result)){
echo $row["field1"];
// field1;
echo $row["field2"];
// field2;
}
|
v0.2 Example 1
Send mysql query using sql_query()
function
|
<?
// include the class file
include_once "database.class.php";
// create the class object
$sql=new
sql_class;
// define mysql information
$sql->sql_host="localhost";
$sql->sql_db="";
$sql->sql_user="";
$sql->sql_pass="";
// send mysql query
$result=$sql->sql_query("select
* from table");
//
get number of rows in mysql query result
$sql_record_count=$sql->sql_num_rows($result);
// fetch a result row as an associative
array, a numeric array, or both
while($row=$sql->sql_fetch_array($result)){
echo
$row["field1"];
// field1;
echo $row["field2"];
// field2;
}
?>
|
v0.2 Example 2
Send mysql query using sql_process()
function instead of sql_query() function. No need to run the opendb()
and closedb() function.
|
<?
// include the class file
include_once "database.class.php";
// create the class object
$sql=new
sql_class;
// define mysql information
$sql->sql_host="localhost";
$sql->sql_db="";
$sql->sql_user="";
$sql->sql_pass="";
// send mysql query and auto connection
and close database
$result=$sql->sql_process("select
field1,field2 from table");
// get number of rows in mysql query
result
$sql_record_count=$sql->sql_num_rows($result);
// fetch a result row as an associative
array, a numeric array, or both
while($row=$sql->sql_fetch_array($result)){
echo
$row["field1"];
// field1;
echo $row["field2"];
// field2;
}
?>
|
v0.2 Example 3
Send mysql query using sql_process()
function. Using sql_process() function first then sql_num_rows(), sql_fetch_row()
and sql_fetch_array() function no need to assign the mysql resource result.
|
<?
// include the class file
include_once "database.class.php";
// create the class object
$sql=new
sql_class;
// define mysql information
$sql->sql_host="localhost";
$sql->sql_db="";
$sql->sql_user="";
$sql->sql_pass="";
// send mysql query and auto connection
and close database
$result=$sql->sql_process("select
field1,field2 from table");
// get number of rows in mysql query
result
$sql_record_count=$sql->sql_num_rows();
// fetch a result row as an associative
array, a numeric array, or both
while($row=$sql->sql_fetch_array()){
echo
$row["field1"];
// field1;
echo $row["field2"];
// field2;
}
?>
|
Version
0.1
Open database
Close database
Send mysql query
|
$result=$sql->sql_query("select
* from table");
|
v0.1 Example
|
<?
// include the class file
include_once "database.class.php";
// create the class object
$sql=new
sql_class;
// define mysql information
$sql->sql_host="localhost";
$sql->sql_db="";
$sql->sql_user="";
$sql->sql_pass="";
// open database connection
$sql->opendb();
// send mysql query
$result=$sql->sql_query("select
* from table");
// close database connection
$sql->closedb();
?>
|
ChangeLog
Version 0.8 (2003-12-29)
- Removed sql_field_table()
function.
- Removed sql_field_name()
function.
- Removed sql_show_fields()
function.
- Added new function sql_table_fields().
- Added new function sql_data_seek().
Version 0.7 (2003-11-24)
- Added "set_debug_error_reporting"
parameter.
- Added new function php_debug_error_reporting().
Version 0.6 (2003-08-25)
- Added "opendb_status"
parameter.
- Added "sql_lift_connect"
parameter.
- Improved opendb() function.
- Improved closedb() function.
- Improved sql_query() function.
Version 0.5 (2003-01-21)
- Changed "version"
parameter value.
- Changed "show_error"
parameter value default to false.
- Changed "set_error_reporting"
parameter value to empty.
- Improved sql_class() function.
- Fixed bug in opendb() function.
"$this->show_sql_error();" may show duplicate error message
so removed.
- Improved the show_sql_error()
function.
- Removed "admin_show_error"
parameter.
Version 0.4 (2003-01-13)
- Added "show_error"
parameter.
- Added "set_error_reporting"
parameter.
- Added "version"
parameter.
- Added new function sql_class().
- Improved the opendb() function.
- Improved the sql_query()
function.
- Added new function php_error_reporting().
- Added new function show_sql_error().
Version 0.3 (2002-12-20)
- Added new function check_connection().
- Added new function sql_num_fields().
- Added new function sql_field_table().
- Added new function sql_field_name().
- Added new function sql_show_fields().
- Added new function sql_reset().
Version 0.2 (2002-12-02)
- Added "querystring"
parameter.
- Added new function sql_process().
- Changed sql_query() function
to use opendb() and closedb() automatically.
- Added new function sql_fetch_row().
- Added new function sql_fetch_array().
- Added new function sql_num_rows().
Version 0.1 (2002-11-13)
- Added "sql_host" parameter
to define mysql host.
- Added "sql_db"
parameter to define mysql database.
- Added "sql_user"
parameter to define mysql username.
- Added "sql_pass"
parameter to define mysql password.
- Added new function opendb().
- Added new function closedb().
- Added new function sql_query().
|