التخطي إلى المحتوى الرئيسي

Database Connectivity in Wordpress,Wordpress database tutorial

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:-

$wpdb->insert( 
    'table', 
    array( 
        'column1' => 'value1', 
        'column2' => 123 
    ), 
);

Syntax for data updation:-


$wpdb->update( 
    'table', 
    array( 
        '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:-
<?php
/*
Template name:   Student Template
*/
get_header();
?>
<section>
<div style="margin-left: 50px;margin-top: 50px;float:left;">
<form action="" method="post">
  
     <input type="text" name="txtrno" placeholder="Enter rno" />
     <br>
     <br>
     <input type="text" name="txtsname" placeholder="Enter name" />
      <br>
      <br>
       <input type="text" name="txtbranch" placeholder="Enter branch" />
<br>
<br>
 <input type="text" name="txtsem" placeholder="Enter sem" />
 <br>
 <br>
      <input type="submit" name="btnsubmit" value="Submit" />

 </form>

 <?php
     global $wpdb;
     if(isset($_REQUEST['btnsubmit']))
     {
        $rno=$_REQUEST['txtrno'];
        $sname=$_REQUEST['txtsname'];
        $branch=$_REQUEST['txtbranch'];
        $sem=$_REQUEST['txtsem'];
        $res= $wpdb->insert('wp_student', 
        array( 'rno' => $rno, 
        'sname' =>$sname,
        'branch'=>$branch,
        '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>
<div style="margin-left: 40px;margin-top: 50px;float:left;">
<p>View Student Record Here</p>
<table border="1">
<tr><th>RNO</th><th>Sname</th><th>Branch</th><th>Sem</th></tr>
  <?php

  $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>";
   }
    
  ?>
</table>
</div>
</section>
<?php
get_footer();
?> 











تعليقات

المشاركات الشائعة من هذه المدونة

DSA in C# | Data Structure and Algorithm using C#

  DSA in C# |  Data Structure and Algorithm using C#: Lecture 1: Introduction to Data Structures and Algorithms (1 Hour) 1.1 What are Data Structures? Data Structures are ways to store and organize data so it can be used efficiently. Think of data structures as containers that hold data in a specific format. Types of Data Structures: Primitive Data Structures : These are basic structures built into the language. Example: int , float , char , bool in C#. Example : csharp int age = 25;  // 'age' stores an integer value. bool isStudent = true;  // 'isStudent' stores a boolean value. Non-Primitive Data Structures : These are more complex and are built using primitive types. They are divided into: Linear : Arrays, Lists, Queues, Stacks (data is arranged in a sequence). Non-Linear : Trees, Graphs (data is connected in more complex ways). Example : // Array is a simple linear data structure int[] number...

JSP Page design using Internal CSS

  JSP is used to design the user interface of an application, CSS is used to provide set of properties. Jsp provide proper page template to create user interface of dynamic web application. We can write CSS using three different ways 1)  inline CSS:-   we will write CSS tag under HTML elements <div style="width:200px; height:100px; background-color:green;"></div> 2)  Internal CSS:-  we will write CSS under <style> block. <style type="text/css"> #abc { width:200px;  height:100px;  background-color:green; } </style> <div id="abc"></div> 3) External CSS:-  we will write CSS to create a separate file and link it into HTML Web pages. create a separate file and named it style.css #abc { width:200px;  height:100px;  background-color:green; } go into Jsp page and link style.css <link href="style.css"  type="text/css" rel="stylesheet"   /> <div id="abc"> </div> Exam...

Top 50 Most Asked MERN Stack Interview Questions and Answers for 2025

 Top 50 Most Asked MERN Stack Interview Questions and Answers for 2025 Now a days most of the IT Company asked NODE JS Question mostly in interview. I am creating this article to provide help to all MERN Stack developer , who is in doubt that which type of question can be asked in MERN Stack  then they can learn from this article. I am Shiva Gautam,  I have 15 Years of experience in Multiple IT Technology, I am Founder of Shiva Concept Solution Best Programming Institute with 100% Job placement guarantee. for more information visit  Shiva Concept Solution 1. What is the MERN Stack? Answer : MERN Stack is a full-stack JavaScript framework using MongoDB (database), Express.js (backend framework), React (frontend library), and Node.js (server runtime). It’s popular for building fast, scalable web apps with one language—JavaScript. 2. What is MongoDB, and why use it in MERN? Answer : MongoDB is a NoSQL database that stores data in flexible, JSON-like documents. It...