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

Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
MySQL & ODBC Examples
« 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
  1. include "C:\scriptbasic\include\mysql.bas"
  2.  
  3. dbh = mysql::RealConnect("host","user","password","DB")
  4.  
  5. mysql::query(dbh,"SELECT * FROM bible WHERE word_name LIKE 'am%'")
  6.  
  7. WHILE mysql::FetchHash(dbh, column)
  8.  
  9.   PRINT LEFT(column{"word_name"} & STRING(30," "),30),column{"word_count"},"\n"
  10.  
  11. WEND
  12.  
  13. mysql::Close(dbh)
  14.  

Code: Text
  1. include "C:\scriptbasic\include\odbc.bas"
  2.  
  3. dbh = odbc::RealConnect("DSN","user","password")
  4.  
  5. odbc::query(dbh,"SELECT * FROM bible WHERE word_name LIKE 'am%'")
  6.  
  7. WHILE odbc::FetchHash(dbh,column)
  8.  
  9.   PRINT LEFT(column{"word_name"} & STRING(30," "),30),column{"word_count"},"\n"
  10.  
  11. WEND
  12.  
  13. odbc::Close(dbh)
  14.  

Code: Text
  1. C:\scriptbasic\test>odbctest
  2. am                            164
  3. ama                           1
  4. amabit                        1
  5. amad                          1
  6. amalek                        15
  7. amalekites                    9
  8. amam                          1
  9. amazed                        1
  10. ambassadors                   2
  11. ambrose                       2
  12. ambrosianum                   1
  13. ambush                        7
  14. amen                          15
  15. amend                         1
  16. amending                      1
  17. amends                        1
  18. amerce                        1
  19. amethyst                      2
  20. ammiel                        1
  21. ammihud                       7
  22. amminadab                     6
  23. ammishaddai                   5
  24. ammon                         38
  25. ammonite                      1
  26. ammonites                     1
  27. among                         281
  28. amongst                       2
  29. amorite                       9
  30. amorites                      62
  31. amos                          1
  32. amram                         6
  33. amram's                       1
  34. amramites                     1
  35. amraphel                      2
  36.  

The ODBC example is using the MySQL ODBC Connector driver. Both examples are accessing the same MySQL database table and produce the same results.