A class written by Cainiao to operate MYSQL databases is very abnormal. Please correct or request similar code

Source: Internet
Author: User
A class written by beginners to operate MYSQL databases has many errors. Please correct or ask for similar code & lt ;? Php & nbsp; class & nbsp; TDbOpr {& nbsp; public & nbsp; var & nbsp; $ cn & nbsp; new & nbsp; mysqli (& #39; a class written by localho beginners to operate MYSQL databases, with many errors. Please correct or request similar code
Class TDbOpr
{
Public var $ cn = new mysqli ('localhost', 'root', 'sa ', 'test ');
// Connect to the database
Function Connected ()
{
Return $ cn-> mysqli_connect_errno = 0;
}
// Execute the SQL statement
Function Execute ($ S)
{
$ Cn-> query ($ S );
Return $ cn-> errno = 0;
}
// Read data
Function ReadData ($ S, & $ ResultData)
{
$ ResultData = $ cn-> query ($ S );
Return $ cn-> errno = 0;
}
// Close the connection
Function Close ()
{
$ Cn-> close ();
}
// Call an instance
Var $ db = new TDbOpr ();
If ($ db-> Connected ())
{
Echo "the database is connected successfully. ";
}
Else
{
Echo "database connection failed. ";
}
?>

------ Solution --------------------

Class TDbOpr
{
Public var $ cn = new mysqli ('localhost', 'root', 'sa ', test );
// Connect to the database
Function Connected ()
{
Return $ cn-> connect_errno <> 0;
}
// Execute the SQL statement
Function Execute ($ S)
{
$ Cn-> query ($ S );
Return $ cn-> errno <> 0;
}
// Read data
// Execute the SQL statement
Function ReadData ($ S, & $ ResultData)
{
ResultData = $ cn-> query ($ S );
Print_r ($ ResultData );
Echo'
';
Echo $ cn-> errno;
Return $ cn-> errno <> 0;
}
// Close the connection
Function Close ()
{
$ Cn-> close ();
}
}

?>

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.