Sql kodlarımız
CREATE TABLE IF NOT EXISTS `users` ( `user_id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(255) NOT NULL, PRIMARY KEY (`uye_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; -- -- Tablo döküm verisi `users` -- INSERT INTO `users` (`user_id`, `username`) VALUES (1, 'admin'),(2, 'test'),(3, 'user');
Php kodarımız
<?php ///////////////////////BAGLANTI FONKSIYONUMUZ////////////////////////// function pdo_mysql_baglan($HOST,$NAME,$USER,$PASS,$CHAR){ return $GLOBALS["baglan"]=array(0=>"mysql:host=$HOST;dbname=$NAME;charset=$CHAR",1=>"$USER",2=>"$PASS"); } //////////////////////////////////////////////////////////////////////////////////// pdo_mysql_baglan("localhost","wordpress","root","123456","utf8"); $pdo = new pdo($baglan[0],$baglan[1],$baglan[2]); $query = $pdo->query("SELECT * FROM users"); foreach( $query->fetchAll(PDO::FETCH_ASSOC) as $data){ echo $data["username"]; echo "<br>"; } ?>