DEDECMS Two-time development directory point this:dedecms two-time development Tutorials Directory
The system will automatically load the dedesql.class.php file and use
$dsql = $db = new Dedesql (false);
The database connection is initialized, so there is no need to initialize the class separately in all the files in the project, which can be manipulated directly with the $dsql or $db, and to prevent errors, you do not have to close the database when you are done.
Common methods:
1, execute a non-query type of SQL statements, such as INSERT, create, update and so on
$rs = $db->executenonequery ($sql);
The return value is whether the execution was successful.
2. Executes a non-query-type SQL statement and returns the number of successful records
$rs = $db->executenonequery2 ($sql);
Compared to the above, it returns the number of records affected, not the Boolean value
3. Return a single record
$arr = $db->getone ($sql);
$dsql If you do not have a limit, the system automatically adds the limit 0,1
4. Execute Conditional Query statement
$db->setquery ($dsql), $db->execute (), while ($arr = $db->getarray ()) {} $db->setquery ($dsql), $db Execute (); while ($arr = $db->getarray ()) {}
Can be simplified to:
$db->execute (' Me ', $dsql), while ($arr = $db->getarray ()) {} $db->execute (' Me ', $dsql) and while ($arr = $db GetArray ()) {}
' Me ' is a recordset cursor that distinguishes between different queries, such as:
$db->execute (' Me ', $dsql), while ($arr = $db->getarray ()) {$db->execute (' 2 ', $dsql 2) and while ($arr 2 = $db GetArray ()) {}} $db->execute (' Me ', $dsql), while ($arr = $db->getarray ()) {$db->execute (' 2 ', $dsql 2); ARR2 = $db->getarray ()) {}}
In this case, you must specify a value to differentiate the default ' me ' parameter, or else an error will occur
$db->getarray ($rsid, $acctype) parameter $rsid= "Me" $acctype =mysql_assoc
Reading data in a query cursor can also be used
$db->getobject ($rsid = "Me");
The returned result is a value represented by the class structure.
5. Get the last inserted auto-increment primary Key ID value
$db->getlastid ();
6, the total number of records to obtain the query
$db->gettotalrow ($rsid = "Me")
7. Get the MySQL version number
$db->getversion ($isformat =true)
By default, it is converted to x.xx form floating point number
8. Analyze the resources of a query
$db->freeresult ($rsid = "Me");
9. If a data table exists in the database
$db->istable ($tbname)
10. Re-select the database you want to manipulate
$db->selectdb ($dbname);
11. Get the database connection ID
$db->linkid
Once you have this connection ID, you can perform database operations directly with MySQL related functions
In a non-forced situation, this variable is not normally used in the project.
DEDECMS Two-time development: Dedesql.class.php Database Class