Open Sage

ScriptBasic => Language Features => Topic started by: root on May 23, 2026, 06:31 PM

Title: MySQL Entension Module
Post by: root on May 23, 2026, 06:31 PM
ScriptBasic supports MySQL with a C API interface that is lightening fast. I don't have the MySQL Classic  Models example DB on my Windows laptop so these examples will be from my Linux servers.

' MySQL Test Program

IMPORT mysql.bas

dbh = mysql::RealConnect("localhost","root","PASSWORD","classicmodels")

mysql::query(dbh,"SELECT * FROM products LIMIT 25")

WHILE mysql::FetchHash(dbh,column)
  PRINT column{"productCode"}," - ",column{"productName"}," - ",FORMAT("%~$###.00~",column{"MSRP"}),"\n"
WEND

PRINTNL
PRINT "The database handle is: ",dbh,"\n"
PRINT "Affected rows by SELECT: ",mysql::AffectedRows(dbh),"\n"
PRINT "Character set name is: ",mysql::CharacterSetName(dbh),"\n"
PRINT "Last error is: ",mysql::ErrorMessage(dbh),"\n"
PRINT "Client info is: ",mysql::GetClientInfo(),"\n"
PRINT "Host info is: ",mysql::GetHostInfo(dbh),"\n"
PRINT "Proto info is: ",mysql::GetProtoInfo(dbh),"\n"
PRINT "Server info is: ",mysql::GetServerInfo(dbh),"\n"
PRINT "PING result: ",mysql::Ping(dbh),"\n"
PRINT "Thread ID: ",mysql::ThreadId(dbh),"\n"
PRINT "Status is: ",mysql::Stat(dbh),"\n"

mysql::Close(dbh)

Output:
rs@linux-dev:~/sbrt/examples$ sbc testmysql.sb
S10_1678 - 1969 Harley Davidson Ultimate Chopper - $ 95.70
S10_1949 - 1952 Alpine Renault 1300 - $214.30
S10_2016 - 1996 Moto Guzzi 1100i - $118.94
S10_4698 - 2003 Harley-Davidson Eagle Drag Bike - $193.66
S10_4757 - 1972 Alfa Romeo GTA - $136.00
S10_4962 - 1962 LanciaA Delta 16V - $147.74
S12_1099 - 1968 Ford Mustang - $194.57
S12_1108 - 2001 Ferrari Enzo - $207.80
S12_1666 - 1958 Setra Bus - $136.67
S12_2823 - 2002 Suzuki XREO - $150.62
S12_3148 - 1969 Corvair Monza - $151.08
S12_3380 - 1968 Dodge Charger - $117.44
S12_3891 - 1969 Ford Falcon - $173.02
S12_3990 - 1970 Plymouth Hemi Cuda - $ 79.80
S12_4473 - 1957 Chevy Pickup - $118.50
S12_4675 - 1969 Dodge Charger - $115.16
S18_1097 - 1940 Ford Pickup Truck - $116.67
S18_1129 - 1993 Mazda RX-7 - $141.54
S18_1342 - 1937 Lincoln Berline - $102.74
S18_1367 - 1936 Mercedes-Benz 500K Special Roadster - $ 53.91
S18_1589 - 1965 Aston Martin DB5 - $124.44
S18_1662 - 1980s Black Hawk Helicopter - $157.69
S18_1749 - 1917 Grand Touring Sedan - $170.00
S18_1889 - 1948 Porsche 356-A Roadster - $ 77.00
S18_1984 - 1995 Honda Civic - $142.25

The database handle is: 1
Affected rows by SELECT: 25
Character set name is: utf8mb4
Last error is:
Client info is: 8.0.44
Host info is: Localhost via UNIX socket
Proto info is: 10
Server info is: 8.0.44-0ubuntu0.24.04.2
PING result: -1
Thread ID: 0
Status is: Uptime: 837  Threads: 2  Questions: 1039  Slow queries: 0  Opens: 470  Flush tables: 3  Open tables: 389  Queries per second avg: 1.241
jrs@linux-dev:~/sbrt/examples$

THIS (https://sbqbo.org/home/sbajax) MySQL example is using AJAX to select the product line to display.This is running on the ScriptBasic web server.