1
+ #include once "mysql\mysql.bi"
2
+
3
+ #define NULL 0
4
+
5
+ dim db as MYSQL ptr
6
+ dim dbname as string
7
+
8
+ db = mysql_init( NULL )
9
+
10
+ dbname = "tel1"
11
+
12
+ if ( mysql_real_connect( db, "localhost" , "auios" , "5018" , NULL, MYSQL_PORT, NULL, 0 ) = 0 ) then
13
+ print "Can't connect to the mysql server on port" ; MYSQL_PORT
14
+ mysql_close( db )
15
+ sleep()
16
+ end 1
17
+ end if
18
+
19
+ if ( mysql_select_db( db, dbname ) ) then
20
+ print "Can't select the " ; dbname ; " database !"
21
+ mysql_close( db )
22
+ sleep()
23
+ end 1
24
+ end if
25
+
26
+ print "Client info: " ; *mysql_get_client_info()
27
+
28
+ print "Host info: " ; *mysql_get_host_info( db )
29
+
30
+ print "Server info: " ; *mysql_get_server_info( db )
31
+
32
+ dim res as MYSQL_RES ptr
33
+ dim fd as MYSQL_FIELD ptr
34
+ dim row as MYSQL_ROW
35
+ dim as integer l, x, j, k
36
+ dim fields( 24 ) as string
37
+ dim rowstr as string
38
+
39
+ res = mysql_list_tables( db, "%" )
40
+ l = 1
41
+ x = 0
42
+ do
43
+ fd = mysql_fetch_field( res )
44
+ if ( fd = NULL ) then
45
+ print "Fetch field"
46
+ exit do
47
+ end if
48
+
49
+ fields(x) = *fd->name
50
+ do
51
+ row = mysql_fetch_row( res )
52
+ if ( row = NULL ) then
53
+ print "Fetch row"
54
+ exit do
55
+ end if
56
+
57
+ j = mysql_num_fields( res )
58
+ print "Table #" ; l ; " :-"
59
+ l += 1
60
+ for k = 0 to j- 1
61
+ print " Fld #" ; k+ 1 ; "(" + fields(k) + "): " ;
62
+ if ( row[k] = NULL ) then
63
+ print "NULL"
64
+ else
65
+ rowstr = *row[k]
66
+ print rowstr
67
+ end if
68
+ print "=============================="
69
+ next
70
+ loop
71
+
72
+ mysql_free_result( res )
73
+ x += 1
74
+ loop
75
+
76
+ print mysql_query(db, "SELECT * FROM bookinventory" )
77
+ res = mysql_store_result(db)
78
+ dim as integer numFields = mysql_num_fields(res)
79
+
80
+ do
81
+ row = mysql_fetch_row(res)
82
+ if (row = NULL) then exit do
83
+ dim as string outputBuilder
84
+ for colIdx as integer = 0 to numFields- 1
85
+ outputBuilder+=*row[colIdx]
86
+ outputBuilder+= " | "
87
+ next colIdx
88
+ print outputBuilder
89
+ loop
90
+
91
+ mysql_free_result(res)
92
+
93
+
94
+ mysql_close( db )
95
+ sleep()
0 commit comments