Rookie wrote an operation MySQL database class, unusually heavy. Please correct or ask for similar code
Source: Internet
Author: User
Beginners write an operation MySQL database class, the error is heavy. Please correct or ask for similar code
Class TDBOPR
{
public var $cn = new mysqli (' localhost ', ' root ', ' sa ', ' test ');
Connecting to a database
function Connected ()
{
return $CN Mysqli_connect_errno = = 0;
}
Execute SQL statement
function Execute ($S)
{
$CN, query ($S);
return $CN errno = = 0;
}
Reading data
function ReadData ($S, & $ResultData)
{
$ResultData = Query ($S), $CN
return $CN errno = = 0;
}
Close connection
function Close ()
{
$CN-Close ();
}
Invoke instance
var $db = new Tdbopr ();
if ($db, Connected ())
{
echo "The database connection was successful. ";
}
Else
{
echo "Database connection failed. ";
}
?>
------Solution--------------------
Class TDBOPR
{
public var $cn = new mysqli (' localhost ', ' root ', ' sa ', test);
Connecting to a database
function Connected ()
{
return $CN connect_errno <> 0;
}
Execute SQL statement
function Execute ($S)
{
$CN, query ($S);
return $CN errno <> 0;
}
Reading data
Execute SQL statement
function ReadData ($S, & $ResultData)
{
Resultdata = $cn, query ($S);
Print_r ($ResultData);
Echo '
';
Echo $CN-errno;
return $CN errno <> 0;
}
Close connection
function Close ()
{
$CN-Close ();
}
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.