<?php /* DEDECMS Database Usage Example description */ Require_once dirname (__file__). " Pub_db_mysql.php ";//reference database file Ensure database information is filled in correctly Database connection Information $cfg _dbhost = ' localhost '; $cfg _dbname = ' sccms '; $cfg _dbuser = ' root '; $cfg _dbpwd = ' 123456 '; $cfg _dbprefix = ' sc_ '; $cfg _db_language = ' UTF8 '; Create a new database operation class $dsql = new Scsql (false); Gets the contents of a record/////////////////////////////// Here's how to get a record using an instance $row = $dsql->getone ("select * from dede_* where id = $aid"); Gets the contents of the data stored in the array $row, which can be called out by subscript echo $row [' id ']; Here is the loop call record /////////////////////////////////////////////////////////////////////////////// To get the total number of queries output///////////////////////////// Gets the total number of records for a query $row = $dsql->getone ("SELECT count (*) as DD where typeid = $typeid"); echo $row [' dd '];//output total /////////////////////////////////////////////////////////////////////////////// Outputs several records of a query////////////////////////////////// $sql = "SELECT * from dede_*"; $dsql->setquery ($sql);//Format SQL query statements $dsql->execute ();//Execute SQL operation Executing results from a query through the loop output while ($row = $dsql->getarray ()) { echo $row [' id ']; echo $row [' title ']; } or output the content in this way while ($row = $dsql->getobject ()) { Echo $row->id; Echo $row->title; } /////////////////////////////////////////////////////////////////////////////// Insert a record/////////////////////////////// $sql = " INSERT into ' Dede_member_flink ' (mid,title,url,linktype,imgurl,imgwidth,imgheight) VALUES (". $cfg _ml->m_id.", ' $title ', ' $url ', ' $linktype ', ' $imgurl ', ' $imgwidth ', ' $imgheight '); /Insert Record Database $dsql->setquery ($sql);//FORMAT query statement $dsql->execnonequery ();//Execute SQL operation /////////////////////////////////////////////////////////////////////////////// Delete a record/////////////////////////// $sql = "Delete from Dede_member_flink where aid= ' $aid ' and mid= '". $cfg _ml->m_id. "';"; $dsql->setquery ($sql); $dsql->execnonequery (); or use simplified mode $dsql->execnonequery ("Delete from Dede_member_flink where aid= ' $aid ' and mid= '". $cfg _ml->m_id. "';"); /////////////////////////////////////////////////////////////////////////////// Update a record////////////////////////// $upquery = " Update Dede_member_flink Set Title= ' $title ', url= ' $url ', linktype= ' $linktype ', Imgurl= ' $imgurl ', imgwidth= ' $imgwidth ', imgheight= ' $imgheight ' where aid= ' $aid ' and mid= ' ". $cfg _ml->m_id." '; "; $rs = $dsql->executenonequery ($upquery); /////////////////////////////////////////////////////////////////////////////// A common method for judging the contents of a database/////////////////// $row = $dsql->getone ("select * from Dede_moneycard_type where tid={$pid}"); if (!is_array ($row)) { echo "Failure"; Exit (); } ///////////////////////////// $upquery = "Update Dede_member_flink set Title= ' $title ', url= ' $url ', linktype= ' $linktype ', Imgurl= ' $imgurl ', imgwidth= ' $imgwidth ', imgheight= ' $imgheight ' where aid= ' $aid ' and mid= ' ". $cfg _ml->m_id." '; "; $rs = $dsql->executenonequery ($upquery); if ($rs) { echo "Success"; }else{ echo "Failure"; } Get Total////////////////////////////////// $dsql = new Dedesql (false); $dsql->setquery ("select * from ' dede_admin ' where userid= ' $userid ' Or uname= ' $uname '"); $dsql->execute (); $ns = $dsql->gettotalrow (); Close Database/////////////////////////////////// $dsql->close (); /////////////////////////////////////////////////////////////////////////////// ?> |