Copy link to clipboard
Copied
Is there any script to import data from mysql and use it as variable data?
Currently the option I'm looking at is getting data from mysql and using a json to csv converter and then using the csv in variable data.
However it seems like this is quite tiresome and can cause some errors if there's any invalid characters or problems int he json to csv.
I'm running cc2019 illustrator. Any ideas how this can be accomplished?
1 Correct answer
Illustrator doesn't have any abilities to connect databases. However, We can use CEP infrastructure with NPM.
Here is a sample of V8 side script that connects MySQL and throws command to get return values.
...var csi = new CSInterface();
$("#get").click(function() {
var mysql = require('mysql');
var connection = mysql.createConnection({
host : '<MySQL Server address>',
port : '<Port: probably 3306>',
user : '<database user>',
password : '<user password>',
database : '<database name>'
Explore related tutorials & articles
Copy link to clipboard
Copied
Just use the 'save as csv' feature of your favorite db management software and then you can either use the VariableImporter.jsx script or the native csv-import feature of Illustrator versions CC2018+.
Copy link to clipboard
Copied
yeah, Illustrator does not support mySql format as is, you'll have to export your data to csv preferably.
Copy link to clipboard
Copied
Illustrator doesn't have any abilities to connect databases. However, We can use CEP infrastructure with NPM.
Here is a sample of V8 side script that connects MySQL and throws command to get return values.
var csi = new CSInterface();
$("#get").click(function() {
var mysql = require('mysql');
var connection = mysql.createConnection({
host : '<MySQL Server address>',
port : '<Port: probably 3306>',
user : '<database user>',
password : '<user password>',
database : '<database name>'
});
connection.connect();
var queryString = "SELECT `order_id` AS `order_id`, `size` AS `size`, `quantity_order` AS `quantity_order`, "
+ "`post` AS `post`, `adds` AS `adds`, `name` AS `name`, `delivered` AS `delivered` "
+ "FROM `book_db`.`work_data` AS `work_data` WHERE `delivered` = 0 ORDER BY `size` ASC";
connection.query(queryString, function(err, rows, fields) {
if (err) console.log(err);
else {
var str = "";
for (var i=0;i<rows.length;i++){
str += rows.order_id + "," + rows.size + "," + rows.quantity_order + ","
+ rows.post + "," + rows.adds + "," + rows.name +"\r"
}
csi.evalScript("formatter('" + str + "')");
}
});
Also, you can check about CEP Extensions in below forum.

