ScriptBasic
February 09, 2012, 07:09:22 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: The ScriptBasic User, Developer and extension module guides are available at the WIKI.
 
   Home   Wiki Help Search Login Register  
Pages: [1]
  Print  
Author Topic: MySQL & ODBC Examples  (Read 696 times)
support
Administrator
*****
Posts: 369


« on: July 08, 2010, 11:53:28 PM »

I thought I would post a couple quick examples of using the MySQL C API and ODBC extension modules with ScriptBasic.

Code: (MySQL)
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)

Code: (ODBC)
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)

Code: (Results)
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.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!