MySQL shared module extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi (MySQL Improved Extension) or PDO_MySQL extension should be used.

There are three ways to do it:

1. MySQL shared module

opkg update
opkg install php5-mod-mysql

2. MySQL Improved Extension

opkg update
opkg install php5-mod-mysqli

3. PHP Data Objects plus PDO driver for MySQL

opkg update
opkg install php5-mod-pdo
opkg install php5-mod-pdo-mysql

MySQL shared module sample:

opkg update
opkg install php5-cli
opkg install php5-mod-mysql
nano /mnt/sda1/dbversion.php
#!/usr/bin/php-cli
<?php
$link = mysql_connect("127.0.0.1", "root", "password");
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo "Connected successfully\n";
printf("MySQL server version: %s\n", mysql_get_server_info());
mysql_close($link);
?>
chmod 755 /mnt/sda1/dbversion.php
/mnt/sda1/dbversion.php
Connected successfully
MySQL server version: 5.1.53

MySQL Improved Extension sample:

opkg update
opkg install php5-cli
opkg install php5-mod-mysqli
nano /mnt/sda1/dbversion.php
#!/usr/bin/php-cli
<?php
$link = mysqli_connect("127.0.0.1", "root", "password");
/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
/* print server version */
printf("Server version: %d\n", mysqli_get_server_version($link));
/* close connection */
mysqli_close($link);
?>
chmod 755 /mnt/sda1/dbversion.php
/mnt/sda1/dbversion.php
Server version: 50153

PHP Data Objects plus PDO driver for MySQL sample:

opkg update
opkg install php5-cli
opkg install php5-mod-pdo
opkg install php5-mod-pdo-mysql
nano /mnt/sda1/db.php
#!/usr/bin/php-cli
<?php
try {
    $conn = new PDO("mysql:host=127.0.0.1;dbname=test", "root", "password");
    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "Connected successfully\n";
    }
catch(PDOException $e)
    {
    echo "Connection failed: " . $e->getMessage();
    }
$conn = null;
?>
chmod 755 /mnt/sda1/db.php
/mnt/sda1/db.php
Connected successfully

Write comment (0 Comments)

Use ash script to SQL communication,

install mysql client:

opkg update
opkg install mysql-server
nano mysql.sh
#!/bin/ash
mysql --host=192.168.0.20 --user=root --password=password books<< EOF
INSERT INTO authors (id,name,email) VALUES(4,'ash','[email protected]');
EOF

Write comment (0 Comments)

Use python script to communication mysql:

Install python-mysql:

opkg update
opkg install python-mysql
nano mysql.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
import _mysql
import sys
try:
    	con = _mysql.connect('192.168.0.20', 'root', 'password', 'books')
    	#con.query("SELECT VERSION()")
    	#result = con.use_result()
    	#print "MySQL version: %s" %  result.fetch_row()[0]
	con.query("INSERT INTO authors (id,name,email) VALUES(3,'python','[email protected]')")    
except _mysql.Error, e:  
    	print "Error %d: %s" % (e.args[0], e.args[1])
    	sys.exit(1)
finally:   
    	if con:
        		con.close()

Write comment (0 Comments)

Google Spreadsheets Python API

https://github.com/burnash/gspread

opkg update
opkg install nano
opkg install python-openssl
opkg install python-expat
opkg install distribute
easy_install gspread

Go to Google Drive and create an empty spreadsheet you will use for testing.

and get spreadsheet id https://docs.google.com/spreadsheet/ccc?key=0Ao9lSur2AThldE1uQk1MVGtWS25vRTBuTXM4NWpGRFE&usp=drive_web#gid=0

nano /mnt/sda1/googledoc.py
#!/usr/bin/python
import gspread
# Login with your Google account
gc = gspread.login('[email protected]', 'googlepassword')
sh = gc.open_by_key('0Ao9lSur2AThldE1uQk1MVGtWS25vRTBuTXM4NWpGRFE')
wks= sh.get_worksheet(0)
wks.update_acell('B2', "it's down there somewhere, let me take another look.")
chmod 755  /mnt/sda1/googledoc.py
/mnt/sda1/googledoc.py

Confirm spreadsheet from Google drive is updated

Write comment (1 Comment)

Subcategories

Expand the Storage at Yun

Languages Supported by Yun

Backup and Recover

Network and Yun

Hardware & Yun

OpenWrt-SDK & Yun