Author Topic: MySQL & ODBC Examples  (Read 11844 times)

Support

  • Administrator
  • *****
  • Posts: 1
    • View Profile
MySQL & ODBC Examples
« on: July 09, 2010, 06:53:28 am »
I thought I would post a couple quick examples of using the MySQL C API and ODBC extension modules with ScriptBasic.

include "C:\scriptbasic\include\mysql.bas"

dbh = mysql::RealConnect("host","user","password","DB")

mysql::query(dbh,"SELECT * FROM bible WHERE word_name LIKE 'am%'")

WHILE mysql::FetchHash(dbh, column)

  PRINT LEFT(column{"word_name"} & STRING(30," "),30),column{"word_count"},"\n"

WEND

mysql::Close(dbh)
 
include "C:\scriptbasic\include\odbc.bas"

dbh = odbc::RealConnect("DSN","user","password")

odbc::query(dbh,"SELECT * FROM bible WHERE word_name LIKE 'am%'")

WHILE odbc::FetchHash(dbh,column)

  PRINT LEFT(column{"word_name"} & STRING(30," "),30),column{"word_count"},"\n"

WEND

odbc::Close(dbh)
 
C:\scriptbasic\test>odbctest
am                            164
ama                           1
amabit                        1
amad                          1
amalek                        15
amalekites                    9
amam                          1
amazed                        1
ambassadors                   2
ambrose                       2
ambrosianum                   1
ambush                        7
amen                          15
amend                         1
amending                      1
amends                        1
amerce                        1
amethyst                      2
ammiel                        1
ammihud                       7
amminadab                     6
ammishaddai                   5
ammon                         38
ammonite                      1
ammonites                     1
among                         281
amongst                       2
amorite                       9
amorites                      62
amos                          1
amram                         6
amram's                       1
amramites                     1
amraphel                      2
 
The ODBC example is using the MySQL ODBC Connector driver. Both examples are accessing the same MySQL database table and produce the same results.