Dede How to use database classes

Source: Internet
Author: User

Dede How to use database classes $dsql

DEDECMS database Operation class, very practical, in two times development is particularly important, this database operation class description is dedicated to everyone's small gift.

Introducing common.inc.php Files

1

Require_once (DirName (__file__). "/include/common.inc.php");

Get the contents of a record

1

2

$row = $dsql->getone ("select * from dede_* where id = $aid");

echo $row [' id '];

To get the total output of the query

1

2

$row = $dsql->getone ("SELECT count (*) as DD where typeid = $typeid");

echo $row [' dd '];//output total

  

Output several records of a query

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

$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;

}

  

Outputs several records of a query dedecms5

1

2

3

4

5

6

7

$dsql->setquery ("Select Id,typename from ' #@__arctype ' where reid=0 and channeltype=1 and Ishidden=0 and Ispart<> ; 2 order by Sortrank ");

$dsql->execute ();

while ($row = $dsql->getobject ())

{

$channellist. = "<a href= ' wap.php?action=list&id={$row->id} ' >{$row->typename}</a>";

Echo $row->id;

}

  

Insert a record

1

2

3

4

5

$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

It has been proved that the above statement is not properly inserted into the database, the following is the correct statement

1

2

3

4

5

$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->executenonequery ($sql);//Execute SQL operation

$gid = $dsql->getlastid ();//Get the ID you just inserted

  

Delete a record

1

2

3

4

5

$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

1

2

3

4

5

6

7

$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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

$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

1

2

3

4

$dsql = new Dedesql (false);

$dsql->setquery ("select * from ' dede_admin ' where userid= ' $userid ' Or uname= ' $uname '");

$dsql->execute ();

$ns = $dsql->gettotalrow ();

  

Close the database

1

$dsql->close ();

  

Instance

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21st

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

<?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 ();

///////////////////////////////////////////////////////////////////////////////

?>

Dede How to use database classes

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.