A Scripting Language for Web, Linux and Windows

A Scripting Language for Web, Linux and Windows

Example: Connect to MySQL database

Demonstrates how to access MySQL databases.
MySQL functions are defined in lib/mysql.inc.v1

Note: You need to install MySQL client libraries.

Try:
apt-get install libmysqlclient-dev
apt-get install default-libmysqlclient-dev
apt-get install libmariadb-dev-compat libmariadb-dev

<?v1
require_once ("lib/mysql.inc.v1");

// Connection parameters
const MYSQL_HOST = "localhost";
const 
MYSQL_PORT = 3306;
const 
MYSQL_USER = "root";
const 
MYSQL_PASSWORD = "";
const 
MYSQL_DATABASE = "mysql";

print (
"Library: ", mySQLLibName);

// Connect to database and read table
mysql = mysql_init ();

if (
mysql && mysql_connect (mysql, MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE, MYSQL_PORT))
{
    print (
        
"Connected to MySQL Server ", 
        
mysql_get_server_info (mysql), 
        
" with Client ", 
        
mysql_get_client_info (mysql)
      );

    
mysql_query (mysql, "set names utf8");

    
// Query a table
    
if ( result=mysql_query (mysql, "select * from user")) {
        
data = array ();

        while (
mysql_fetch_array (result, data)) {
            print (
data["Host"], ";", data["User"]);
        }

        
mysql_free_result (result);
    }
    else {
        print (
mysql_error (mysql));
    }
}
else {
    print (
mysql_error (mysql));
}
mysql_close (mysql);

?>

back to Home