Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Script to import mysql data and use it as variable data

Contributor ,
Feb 12, 2019 Feb 12, 2019

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?

TOPICS
Scripting
711
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 18, 2019 Feb 18, 2019

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>'

 

...
Translate
Adobe
Valorous Hero ,
Feb 12, 2019 Feb 12, 2019

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+.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 13, 2019 Feb 13, 2019

yeah, Illustrator does not support mySql format as is, you'll have to export your data to csv preferably.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 18, 2019 Feb 18, 2019
LATEST

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.

Extensions / Add-ons Development

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines