Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

Database Connectivity in Wordpress,Wordpress database tutorial

Wordpress is complete dynamic CMS of PHP,Wordpress provide database connectity when we install wordpress CMS then we can not say wordpress has database connectivity manually but it is mandatory in installation time.

Wordpress CMS provide table also WP_POST is the most impotent table where we can store records .

Wordpress page and post both store record using this.

Code or database operation.

Wordpress provide global $wpdb for database operation

Step  for database

Database operation in wordpress:-

1)  create database  

 2) create table  as per requirement

 3) create page template to create form

 4)  global $wpdb

Syntax for data selection:-

$wpdb->get_results( "SELECT id, name FROM mytable" );

Syntax for data insertion:-

        'column1' => 'value1', 
        'column2' => 123 

Syntax for data updation:-

        'column1' => 'value1',  // string
        'column2' => 'value2'   // integer (number) 
    array( 'ID' => 1 )

Syntax for data deletion:-

$wpdb->delete( 'table', array( 'ID' => 1 ) );


Complete code of database 
create table in wordpress exiting database

create table wp_student(rno varchar(50),sname varchar(50),branch varchar(50),sem varchar(50))

Code page template:-
Template name:   Student Template
<div style="margin-left: 50px;margin-top: 50px;float:left;">
<form action="" method="post">
     <input type="text" name="txtrno" placeholder="Enter rno" />
     <input type="text" name="txtsname" placeholder="Enter name" />
       <input type="text" name="txtbranch" placeholder="Enter branch" />
 <input type="text" name="txtsem" placeholder="Enter sem" />
      <input type="submit" name="btnsubmit" value="Submit" />


     global $wpdb;
        $res= $wpdb->insert('wp_student', 
        array( 'rno' => $rno, 
        'sname' =>$sname,
        'sem' =>$sem));
      //  $conn= mysqli_connect('localhost','root','','scsdb');
        // mysqli_query($conn,"INSERT INTO `wp_student` (`rno`, `sname`, `branch`, `sem`) VALUES ('g', 's', 's', 's')");



<div style="margin-left: 40px;margin-top: 50px;float:left;">
<p>View Student Record Here</p>
<table border="1">

  $res = $wpdb->get_results( "SELECT rno,sname,branch,sem FROM wp_student");

   foreach ($res as $x) {
    echo "<tr><td>".$x->rno,"</td><td>".$x->sname."</td><td>".$x->branch."</td><td>".$x->sem."</td></tr>";

Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post