Php loop result set

Source: Internet
Author: User
Php loop result set new users This post was last edited by zuoan2008 from 2013-07-0615: 47: 24 class_db.php & lt ;? PhpClass & nbsp; MySQLDB {var & nbsp; $ host; var & nbsp; $ user; var & n php loop result set beginner
This post was last edited by zuoan2008 at 15:47:24 class_db.php

Class MySQLDB
{
Var $ host;
Var $ user;
Var $ passwd;
Var $ database;
Var $ conn;

// Use constructors to initialize variables
// Connect to the database at the same time
Function MySQLDB ($ host, $ user, $ password, $ database)
{
$ This-> host = $ host;
$ This-> user = $ user;
$ This-> passwd = $ password;
$ This-> database = $ database;
$ This-> conn = mysql_connect ($ this-> host, $ this-> user, $ this-> passwd) or die ("cocould not connect to $ this-> host ");
Mysql_select_db ($ this-> database, $ this-> conn) or die ("cocould not switch to database $ this-> database ");
Mysql_query ("set names 'gbk '");
}

// This function is used to close the database connection.
Function Close ()
{
MySQL_close ($ this-> conn );
}

// This function allows you to query databases.
Function Query ($ queryStr)
{
$ Res = Mysql_query ($ queryStr, $ this-> conn );
Return $ res;
}

// This function returns the record set
Function getRows ($ res)
{
$ Rowno = 0;
$ Rowno = MySQL_num_rows ($ res );
If ($ rowno> 0)
{
For ($ row = 0; $ row <$ rowno; $ row ++)
{

$ Rows [$ row] = MySQL_fetch_array ($ res );

// It is originally MySQL_fetch_row, but cannot be extracted as an array. it can only be indexed.

// This makes it easier to use indexes and names.

}

Return $ rows;

}

}

// Number of database records retrieved by this function
Function getRowsNum ($ res)
{
$ Rowno = 0;
$ Rowno = mysql_num_rows ($ res );
Return $ rowno;
}

// The number of fields returned by this function in the database table
Function getFieldsNum ($ res)
{
$ Fieldno = 0;
$ Fieldno = mysql_num_fields ($ res );
Return $ fieldno;

}

// This function returns the database table field name set.
Function getFields ($ res)
{
$ Fno = $ this-> getFieldsNum ($ res );
If ($ fno> 0)
{
For ($ I = 0; $ I <$ fno; $ I ++)
{
$ Fs [$ I] = MySQL_field_name ($ res, $ I); // Obtain the name of the I field
}
Return $ fs;

}

}

}


Login_action.php

    session_start();
include('../config/config_db.php');
include('../class/db/class_db.php');

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.