Notifications
Clear all

[Closed] How to Integrate MySQL and MaxScript

How to use MySQL with 3D Studio Max

1. Download and install/configure a MySQL server. (I like PHPDev since it has such an excellent intaller) http://www.firepages.com.au/

2. Download and Install the ODBC Driver: http://dev.mysql.com/downloads/connector/odbc/3.51.html

[Steps 3-8 from:] [“] http://dev.mysql.com/doc/refman/5.0/en/myodbc-configuration-dsn-windows.html ]]( http://dev.mysql.com/doc/refman/5.0/en/myodbc-configuration-dsn-windows.html )

3. Go to your Administrative Tools in windows. (Start -> Control Panel -> Administrative Tools in XP)

4. Click Data Sources (ODBC)

5. Click the “System DSN” Tab.

6.Click Add

7. Select MySQL

8. Data Source Name: Name of Connection

Description: Description of Connection

Server: Server address

User: Username

Password: 12345… wait I mean the password that you use.

Database: which database you want connected

9. Load 3D Studio Max 8.

10. Open your Listener Window

11. Examples:

Getting Data From a MySQL Database (Database: “test” Table: “TestTable”)

TestConn=createOLEObject “ADODB.Connection”

TestConn.Open “driver={MySQL ODBC 3.51 Driver}; server=localhost; database=test”

recordSet = createOLEObject “ADODB.Recordset”

recordSet.Open “SELECT * from TestTable” TestConn <– Standard SQL Request in “”

var = recordset.GetRows ()

– if you want to select a field of data use: Var.DataArray[i][i]

Sending Data to a MySQL Database (Database: “test” Table: “TestTable”, a table with two fields “id” (autoincremented) and “name” (string)

TestConn=createOLEObject “ADODB.Connection”

TestConn.Open “driver={MySQL ODBC 3.51 Driver}; server=localhost; database=test”

recordSet = createOLEObject “ADODB.Recordset”

recordSet.Open “SELECT * from TestTable” TestConn 1 3 <– last 2 numbers are the ADO cursortype and locktype respectively. For more information read the ADO documentation provided below. All you really need to know, is they allow data to be sent back to the database.

recordSet.AddNew #(“id”, “name”) #(undefined,“jim[size=2]mike”)[/size]

Editing Data in a MySQL Database (Database: “test” Table: “TestTable”, a table with two fields “id” (autoincremented) and “name” (string)

TestConn=createOLEObject “ADODB.Connection”

TestConn.Open “driver={MySQL ODBC 3.51 Driver}; server=localhost; database=test”

recordSet = createOLEObject “ADODB.Recordset”

recordSet.Open “SELECT * from TestTable WHERE id = 1” TestConn 1 3

recordSet.update #(“id”, “name”) #(1,“newname[size=2]”)[/size]

[size=2]
[/size]

Deleting Data From a MySQL Database (Database: “test” Table: “TestTable”, a table with two fields “id” (autoincremented) and “name” (string) where there is a field of [5,$string]

TestConn=createOLEObject “ADODB.Connection”

TestConn.Open “driver={MySQL ODBC 3.51 Driver}; server=localhost; database=test”

recordSet = createOLEObject “ADODB.Recordset”

recordSet.Open “SELECT * from TestTable” TestConn 1 3

recordSet.delete

Creating a New Table in a MySQL Database (Database: “test”)

TestConn=createOLEObject “ADODB.Connection”

TestConn.Open “driver={MySQL ODBC 3.51 Driver}; server=localhost; database=test”

recordSet = createOLEObject “ADODB.Recordset”

recordSet.Open “CREATE TABLE NewTable (field01 INT( 4 ) NOT NULL ,field02 VARCHAR( 128 ) NOT NULL )” TestConn 1 3

//creates a new table with two fields: Field 01 and Field 02. Field 01 is an integer of length 4 and Field 2 is a string with a length of 128. For more information refer to SQL Documentation or just use phpmyadmin and use their fancy dancy interface.

Deleting a Table in a MySQL Database (Database: “test”)

TestConn=createOLEObject “ADODB.Connection”

TestConn.Open “driver={MySQL ODBC 3.51 Driver}; server=localhost; database=test”

recordSet = createOLEObject “ADODB.Recordset”

recordSet.Open “DROP TABLE newtable” TestConn 1 3

———————————-

I’ll try to keep updating this as I learn more.

I found a comprehensive set of documentation on the ADO instruction set:
http://docs.sun.com/source/817-2514-10/Ch11_ADO3.html

For more examples see the 3D Studio Maxscript reference related to SafeArrayWrapper.

  • Gavin Greenwalt
13 Replies

Nice. Thanks!

Never knew you could use “[b]MySQL with 3DS Max”.

[/b]Thanks for sharing.

Consider this my questions post…

Things I could use help with:

Currently Empty… check back later for more questions.

You couldn’t until Max 8

Could you use JSAS http://jsas.joomlasolutions.com/ as your server? It’s a great and open source.

You can use any mysql installer during Step #1. I looked at JSAS briefly and it looks like it is just like PHPDev in that it is an: Apache, MySQL and PHP installer… obviously a different flavor and target audience, but you can think of them as equivalent.

Steps 2+ will still be identical.

I’ll also point out that you can use any Database software in existance that has an ODBC driver. You can already use a microsoft SQL database, Access Databse or even an Excel file just by changing the driver declaration. (See the Max Documentation for a list of options to fill that space with.) If you find some little hodunk database application written as a senior project by some computer engineer that has an ODBC you can install the driver and follow pretty much the same steps to set it up.

I am using this code

-- open sql database and get rows
DogConn = createOLEObject "ADODB.Connection" 
DogConn.Open "driver={MySQL ODBC 3.51.12 Driver}; server=localhost; database=max9"
recordSet = createOLEObject "ADODB.Recordset"
recordSet.Open "SELECT * from Test" DogConn
var = recordser.getRows ()

when i run it i get

-- Unknown property: "getRows" in undefined

if i kill the last line i get

-- Unknown property: "open" in undefined

You have any ideas what is going on?
and how to get data going between max and sql…
what am i doing wrong…
Thank you very much!

 rdg

Gavin,

thanks for sharing!

Georg

3D warrior

you got a typo:
var = recordser.getRows ()
should be
var = recordset.getRows ()

Page 1 / 2