Yun & Compatible
- Details
- Written by Sonny Yu
opkg update opkg install luasql-pgsql
nano pgsql.lua
#!/usr/bin/lua require "luasql.postgres" env = assert(luasql.postgres()) con = assert(env:connect('mypgdatabase', 'postgres', 'password', "192.168.0.240")) -- retrieve a cursor cur = assert(con:execute('select username, password from login')) -- print all rows, the rows will be indexed by field names row = cur:fetch ({}, "a") while row do print(string.format("username: %s, password: %s", row.username, row.password)) -- reusing the table of results row = cur:fetch (row, "a") end -- close everything cur:close() con:close() env:close()
chmod 755 pgsql.lua
./pgsql.lua username: sonnyyu, password: password
Write comment (0 Comments)
- Details
- Written by Sonny Yu
opkg update opkg install php5-cli php5-mod-pdo-pgsql
nano pgsql2.php
#!/usr/bin/php-cli <?php try { $db = new PDO('pgsql:dbname=mypgdatabase;host=192.168.0.240','postgres','password'); # Send errors as exceptions $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); # Run a query $sql = "select username, password from login;"; $results = $db->query($sql); foreach($results as $row) { var_dump($row); } } catch(\Exception $e) { echo $e->getMessage(); } ?>
chmod 755 pgsql2.php
./pgsql2.php array(4) { ["username"]=> string(7) "sonnyyu" [0]=> string(7) "sonnyyu" ["password"]=> string(8) "password" [1]=> string(8) "password" }
Write comment (0 Comments)
- Details
- Written by Sonny Yu
opkg update opkg install php5-cli php5-mod-pgsql
nano pgsql.php
#!/usr/bin/php-cli <?php $db = pg_connect("host='192.168.0.240' user='postgres' password='password' dbname='mypgdatabase'"); $grab_people = pg_query("select username, password from login"); $person = pg_fetch_assoc($grab_people); print_r($person); print pg_last_error(); pg_free_result($grab_people); pg_close($db); ?>
chmod 755 pgsql.php
./pgsql.php Array ( [username] => sonnyyu [password] => password )
Write comment (0 Comments)
- Details
- Written by Sonny Yu
opkg update opkg install python-psycopg
nano postgre.py
#!/usr/bin/python # -*- coding: utf-8 -*- import psycopg try: conn = psycopg.connect("dbname='mypgdatabase' user='postgres' host='192.168.0.240' password='password'") except: print "I am unable to connect to the database" cur = conn.cursor() cur.execute("select username,password from login") rows = cur.fetchall() print "\nShow me the databases:\n" for row in rows: print " ", row[0], " ", row[1]
chmod 755 postgre.py
./postgre.py
Write comment (0 Comments)
Subcategories
Expand the Storage at Yun
Expand the Storage at Yun
Languages Supported by Yun
Languages Supported by Yun
Backup and Recover
Backup and Recover
Network and Yun
Network and Yun
Hardware & Yun
Hardware & Yun
OpenWrt-SDK & Yun
OpenWrt-SDK & Yun
Page 2 of 34