<?PHP
header('Content-Type: text/html; charset=utf-8'); // sayfa header bilgisi
require_once('kgMySQL.class.php'); // sınıfımızı sayfamıza çağırıyoruz
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<title>kgSQL test</title>
<style type="text/css">
body {
margin:20px;
font:0.75em/1.8em tahoma, helvetica, "sans serif";
}
</style>
</head>
<body>
<?PHP
$db =& new kgMySQL(); // veritabanı nesnemiz
$db -> db_set('localhost', 'kgsql', 'root', '2003110'); // mysql bağlantısı kuruyor ve vt' nı seçiyoruz
$db -> query("SET NAMES 'utf8'"); // karakter setimizi bu şekilde tanımlayabiliyoruz
/*
Örnek SQL
-----------------------------------
CREATE TABLE `categories` (
`id` int(10) unsigned NOT NULL auto_increment,
`parent` int(11) NOT NULL,
`line` int(11) NOT NULL,
`name` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=11 ;
INSERT INTO `categories` (`id`, `parent`, `line`, `name`) VALUES
(1, 0, 1, 'Modern Avizeler'),
(2, 1, 2, 'Klasik Avizeler'),
(3, 2, 3, 'Modern Kristallitler'),
(4, 0, 6, 'Masa Lambaları'),
(5, 0, 7, 'Aplikler'),
(6, 4, 8, 'Promosyon'),
*/
################################################################################################
// yeni bir veri eklemek için
#$insert = $db -> query("INSERT INTO categories (id, line, name) VALUES ('', '', 'Denemeeeee')");
// eklenen verinin id'sini almak için
#echo $db -> insert_id;
################################################################################################
// veri güncellemek için
#$update = $db -> query("UPDATE categories SET name = 'yeni isimaaaaaşşçççöööğğğİİİüüüııı' WHERE id = '5asda'");
################################################################################################
// veri silmek için
#$delete = $db -> query("DELETE FROM categories WHERE id = '4'");
################################################################################################
// tablodaki kayıtlı veri sayısını almak için
#echo $db -> number("SELECT count(id) FROM categories");
################################################################################################
// sadece bir veriyi almak için
#$row = $db -> row("SELECT id, name FROM categories WHERE id = '1'");
#echo $row -> id.' - '.$row -> name;
################################################################################################
// birden fazla veri almak için
/*
$rows = $db -> rows("SELECT id, name FROM categories");
if ($rows) {
foreach($rows as $row) {
echo $row -> id.' - '.$row -> name.'<br />';
}
}else{
echo 'Kayıtlı veri bulunamadı!';
}
*/
################################################################################################
// recursive yapıda bir fonksiyon ile kullanım örneği
/*
function recursive($parent) {
global $db;
$rows = $db -> rows("SELECT id, parent, name FROM categories WHERE parent = '$parent'");
if ($rows) {
echo '<ul>';
foreach($rows as $row) {
echo '<li>';
echo $row -> id.' - '.$row -> name;
recursive($row -> id);
echo '</li>';
}
echo '</ul>';
}
}
recursive(0);
*/
################################################################################################
// sayfa içerisinde yapılan toplam sorgu sayısını yazdırmak için
#echo '<p>'.$db -> query_number.'</p>';
################################################################################################
?>
</body>
</html>
|