Setelah selesai installasi, buka phpmyadmin dan buat database dengan nama terserah kalian saja (punya saya trial). Lalu import sql berikut
-- phpMyAdmin SQL Dump -- version 3.5.2 -- -- Host: localhost -- Generation Time: Nov 21, 2013 at 03:56 AM -- Server version: 5.5.25a -- PHP Version: 5.4.4 SET SQL_MODE= "NO_AUTO_VALUE_ON_ZERO" ; SET time_zone = "+00:00" ; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */ ; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */ ; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */ ; /*!40101 SET NAMES utf8 */ ; -- -- Database: `trial` -- -- -------------------------------------------------------- -- -- Table structure for table `folks` -- DROP TABLE IF EXISTS `folks`; CREATE TABLE IF NOT EXISTS `folks` ( ` name ` varchar (80) NOT NULL , `address` varchar (160) NOT NULL , `phone` varchar (13) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -- Dumping data for table `folks` -- INSERT INTO `folks` (` name `, `address`, `phone`) VALUES ( 'Nur Tri Wibowo' , 'Poncobudoyo' , '08562415222' ); /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */ ; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */ ; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */ ; |
show-data.py
# Pyhton - mysql tutorial # # this is a simple code for retrieving data from mysqldb # # author: nur tri wibowo # blog : nordskriving.wordpress.com # import mysql module import mysql.connector as mdb # koneksi ke database. sesuaikan dengan settingan server mysql kalian con = mdb.connect(host = '127.0.0.1' ,user = 'root' ,password = 'password' ,database = 'trial' ) # inisialisasi cursor object method cur = con.cursor() # eksekusi query cur.execute( "SELECT * FROM folks" ) # ambil semua data dari query rows = cur.fetchall() # print data for row in rows: print ( '\nNama : ' + row[ 0 ]) print ( 'Alamat : ' + row[ 1 ]) print ( 'No telp : ' + row[ 2 ] + '\n' ) print ( '--nordksriving.wordpress.com--' ) #close cursor object cur.close() |
Tidak ada komentar:
Posting Komentar