Mysql deprecated after every one use mysqli but its fully oops based concept so beginners something they feel difficult to understand the basic query in mysqli i strongly suggested to this post that kind of persons. here we already created some PDO functions for more flexible purpose. follow below code you should learn PDO basic function.
DATABASE
Create sample database table user_data
CREATE TABLE IF NOT EXISTS `user_data` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title` text NOT NULL, `description` text NOT NULL PRIMARY KEY (`id`) )
BASIC.PHP
<?php function __autoload($name) { require $name . '.php'; } $DBVARS=array( 'username'=>'root', 'password'=>'', 'hostname'=>'localhost', 'db_name'=>'1next2' ); function dbAll($query,$key='') { $q = dbQuery($query); $results=array(); while($r=$q->fetch(PDO::FETCH_ASSOC))$results[]=$r; if(!$key)return $results; $arr=array(); foreach($results as $r)$arr[$r[$key]]=$r; return $arr; } function dbInit(){ if(isset($GLOBALS['db']))return $GLOBALS['db']; global $DBVARS; $db=new PDO('mysql:host='.$DBVARS['hostname'].';dbname='.$DBVARS['db_name'],$DBVARS['username'],$DBVARS['password']); $db->query('SET NAMES utf8'); $db->num_queries=0; $GLOBALS['db']=$db; return $db; } function dbOne($query, $field='') { $r = dbRow($query); return $r[$field]; } function dbLastInsertId() { return dbOne('select last_insert_id() as id','id'); } function dbQuery($query){ $db=dbInit(); $q=$db->query($query); $db->num_queries++; return $q; } function dbRow($query) { $q = dbQuery($query); return $q->fetch(PDO::FETCH_ASSOC); }
INDEX.PHP
dbAll($query) used to show all table record values , dbRow($query) this query used to show particular data or single data value.
<html> <head> </head> <?php include_once('basic.php'); $topics="SELECT * FROM user_data"; $topic_list=dbAll($topics); $one_list=dbRow($topics); ?> <body> <div> <h2>Show All topic</h2> <ul> <?php foreach ($topic_list as $key => $list) { ?> <li><?php echo $list['title'] ?> </li> <?php echo $list['description'] ?> <?php } ?> </ul> </div> <div> <h2>one topic</h2> <ul> <li><?php echo $one_list['title'] ?> </li> <?php echo $one_list['description'] ?> </ul> </div> </body> </html>
Undoubtedly, this article turned out to be considerable for me and I am sure this might be advantageous for many seekers who are beginning with PHP or even for the experienced one. I admire you for this great work. Keep blogging.
ReplyDeleteWebsite Designer in Lucknow | Web design company
misal pav recipe | misal pav | spicy misal pav recipe | misal pav recipe in marathi | misal pav recipe in hindi
ReplyDeletehttps://bayanlarsitesi.com/
ReplyDeleteKayseri
Sinop
Kilis
Hakkari
Q6V
Adana
ReplyDeleteElazığ
Kayseri
Şırnak
Antep
YL0QZ
Erzurum
ReplyDeleteElazığ
Konya
Zonguldak
Eskişehir
APG4H
amasya evden eve nakliyat
ReplyDeleteeskişehir evden eve nakliyat
ardahan evden eve nakliyat
manisa evden eve nakliyat
karaman evden eve nakliyat
BJPUİ
D2ED6
ReplyDeleteYalova Parça Eşya Taşıma
Amasya Parça Eşya Taşıma
Samsun Parça Eşya Taşıma
Bitlis Evden Eve Nakliyat
Bursa Lojistik
63305
ReplyDeleteKeçiören Fayans Ustası
Manisa Lojistik
Probit Güvenilir mi
Aydın Lojistik
Etlik Fayans Ustası
Lbank Güvenilir mi
Kırklareli Şehirler Arası Nakliyat
Zonguldak Parça Eşya Taşıma
Paribu Güvenilir mi
60A04
ReplyDeleteGörüntülü Sohbet
Ergo Coin Hangi Borsada
Binance Kimin
Bitcoin Nedir
Arg Coin Hangi Borsada
Bitcoin Kazanma
Coin Kazma
Binance Borsası Güvenilir mi
Soundcloud Reposts Hilesi