PHP database operations

Source: Internet
Author: User
Tags php database

// Dbhelper. php

<? PHP
Class adoconnection
{
// Open the database connection
Function pconnect ($ IP, $ user, $ PWD, $ database)
{
$ Db = mysql_connect ($ IP, $ user, $ PWD );
If (! $ DB)
{
Print "an error occurs when you connect to the database server". mysql_error ();
Exit;
}
$ Link = mysql_select_db ($ database, $ dB );
If (! $ Link)
{
Print "An error occurred when selecting the database on the server connected". mysql_error ();
Exit;
}
}
// Set the Encoding
Function setunicode ($ codestr)
{
Mysql_query ($ codestr );
}
// Close the database connection
Function connclose ()
{
Mysql_close ();
}
// Execute Database Query
// Return
Function executequery ($ sqlstr)
{
$ Result = mysql_query ($ sqlstr );
If (! $ Result ){
Print "Query Overflow". mysql_error ();
Exit;
}
$ Arr = array (); // used to return the Array (when the table is used)
$ I = 0;
While ($ info = mysql_fetch_array ($ result, mysql_both ))
{
$ Arr [$ I] = $ Info;
$ I ++;
}
Mysql_free_result ($ result );
Return $ arr;
}
}
?>

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.