Stored procedure in codeigniter

Steps To Call Stored Procedure In Codeigniter:

The way you call a stored procedure can depend on how you create it. It’s time to discuss three common ways to create and call a stored procedure in CodeIgniter.

1. Create a stored procedure for select operation.


CREATE PROCEDURE Select_first ()
BEGIN
SELECT * FROM table_name;
END

Now that the Select_first procedure has been created and defined, we can call this procedure at any time in CodeIgniter. In this example, we create a variable, $data, by pointing to the procedure above after loading and initializing the database class in CodeIgniter.

To call this specific procedure within a query:-

       $data = $this->db->query(“CALL Select_first ()”);
       mysqli_next_result($this->db->conn_id);
       $result = $data->result();

2. Create a stored procedure for a delete operation


With a stored procedure that depends on parameters, we can use IN/OUT keyword for passing data into the procedure. Let’s create a stored procedure that will delete a record that has a specific id equal to a variable.

CREATE PROCEDURE Delete_first(IN p_id int(10))
BEGIN
DELETE FROM table_name WHERE id=p_id ;
END

In parameterized stored procedure you can use IN/OUT keyword for passing the data to the procedure. After IN, we are stating that the parameter value we pass to the procedure Delete_first(), whatever sits between ( and ) will then be known as p_id, which we also state is an integer. The variable p_id doesn’t mean anything to us outside of the procedure Delete_first. But, now that we’ve created it, all we need to do is create a variable to call Delete_first() and have the procedure ask for a parameter, which can be done by inserting a? between the parentheses that follow the procedure name.
So let’s create a set of variables, one that holds our number 13 and one that calls the procedure to delete rows with a specific id. Just so you know, you can pass a parameter to the procedure from either the model or the controller.

To call this specific procedure within a query:-

$id = ’13’;
$stored_procedure = “CALL Delete_first(?) “;

$result = $this->db->query($stored_pocedure,array(‘id’=>$id));

With this our task is done. The id value passes into the called stored procedure delete_bar and all the rows that contain a value of 13 are deleted from the table. Now you can simply change the value of $id and define $result again to delete any row with a specific value for the column ‘id’.


3. Create a stored procedure for Insert operation.


 

First, we create a procedure with multiple parameters and call it add_insert. Here it’s an INSERT command for MySQL.

CREATE PROCEDURE add_insert(IN L_first VARCHAR(30), IN L_last VARCHAR(30), IN p_mood VARCHAR(30) )
BEGIN
INSERT INTO table_name (first,last,mood) VALUES (L_first,L_last,p_mood);
END

To call this specific procedure within a query:-

$a_procedure = “CALL add_insert(?,?,?)”;
$a_result = $this->db->query( $a_procedure, array(‘first’=>’Foo’,’last’=>’Bar’,’mood’=>’Testy’) );

This would add a row in the table table_name.

Thanks for reading this article.

Advertisements

Responsive Mobile Toggle Menu With Jquery

simple-clean-responsive-mobile-toggle-menu-plugin-for-jquery

How to use it:

1. Include the required menu.css file in the page and change the break point in the CSS3 media queries as per your needs.

<link rel="stylesheet" href="css/menu.css" type="text/css"/>

2. Create a mobile toggle menu using normal <ul> <li> elements.

<nav class="main<a href="http://www.jqueryscript.net/menu/">Menu</a>">
<label for="toggleMenu" class="menuTitle">MENU</label>
<input type="checkbox" id="toggleMenu" />
<ul class="menu">
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Blog</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>

3. Include the jQuery javascript library at the end of the page.

http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js

4. The jQuery script.

function responsiveMenu() {	
	$('.menuTitle').click(function () {
		$('.menu').slideToggle("slow");
		$('.menu').css({"max-height":"800px"});
	});
};

$(function() {
	$(".menu").css({"display":"none","transition":"none","max-height":"inherit"});
	$("#toggleMenu").remove();
	responsiveMenu();
});

5. The Stylesheet of menu.css

/*
Responsive Mobile Toggle Menu v2.2
Description: Mobile first responsive toggle menu
Author: Danielle Vautier
*/

/*Menu mobile first CSS*/
body{ -webkit-animation: bugfix infinite 1s; }

/*This fixes a chrome/webkit bug for older Android Browsers */
@-webkit-keyframes bugfix { from {padding:0;} to {padding:0;} }

/*Required functional CSS don’t change this bit
CSS styles are at the end! */

.mainMenu {
display:block;
position:relative;
width:100%;
margin:0;
padding:0;
float:left;
}

#toggleMenu {
display: none;
}

#toggleMenu:checked ~ ul {
max-height:100%; /*Make page height*/
opacity:1;
}

.mainMenu > ul {
width:100%;
margin:0;
padding:0;
list-style:none;
float:left;
overflow-y: hidden;
max-height:0;
}

.mainMenu li {
margin:0;
padding:0;
white-space:nowrap;
display:block;
width:100%;
float:left;
}

.mainMenu a, .mainMenu a:visited {
display:block;
width:100%; /*required to make whole element clickable*/
}

label.menuTitle {
margin:0;
display:block;
cursor:pointer;
background: url(‘../images/menu.png’);
background-image: url(‘../images/menu.svg’), none;
background-repeat: no-repeat;
background-position: 97% 10px;
background-size: 24px 19px; /*Make same size as your menu.png*/
}

@media screen and (min-width:768px) {
label.menuTitle {
display:none;
}

.mainMenu ul {
display:block!important;
border:0;
overflow:visible;
max-height:100%!important;
}

.mainMenu ul li {
width:auto;
display:inline;
border:0;
}
}
/*Menu Styling CSS – change the below to suit your site!*/
.mainMenu {
border-bottom:1px solid #ccc;
text-align: center;
}

.mainMenu li {
border-top:1px solid #ccc;
}

.mainMenu a, .mainMenu a:visited {
color:#333;
text-decoration:none;
width:94%; /*Use 100% and box-sizing if not supporting ie7*/
padding:5px 3%;
background: none;
}

label.menuTitle {
font-size:20px;
width:94%; /*Use 100% and box-sizing if not supporting ie7*/
padding:6px 3%;
font-weight:bold;
}

@media screen and (min-width:768px) {

.mainMenu li {
border:0;
}

.mainMenu a:hover {
color:#767676;
}

.mainMenu a, .mainMenu a:visited {
padding:10px 3px 10px 8px;
}
}

 

Mumbai University stops BSc IT course

The University of Mumbai (MU) has decided to close the BSc Information Technology (IT) course that the university’s department of IT runs.

The course was one of the few undergraduate courses offered by the varsity.

The decision, that is said to allow the varsity to focus on PG education and research, has instigated protests who said that it will be a loss for students.

Continue reading “Mumbai University stops BSc IT course”

PHP Web Constellations

PHP is one of the best choice for creating web applications. Because it supports advanced web constellations. It supports most of the popular databases, libraries. PHP script can be embedded  with hypertext and client-side script.

With these collective integration, PHP as an open-source attracts people in web development businesses. Currently, most renowned websites are using PHP. For example, Google, Facebook, Yahoo! and more.  As per 2013 metrics made by online research agencies like Netcraft, more than 200 million websites is using PHP.

Rajinikanth’s Kabali day 2 box office collection: Did the movie make Rs 250 crore on first day?

Rajinikanth’s Kabali has shown that it is critic-proof with its massive box office collections. Even as mixed responses came in from reviewers, Kabali is smashing BO records with its collections. Shows are seeing 90 percent occupancy in south India and even Hindi shows have recorded over 50% occupancy on Kabali day 2 screening on Saturday.

With its day 1 earnings of approximately Rs 42 crore, the film is looking at over Rs 120 crore weekend business. On Friday, the film made Rs 21.5 crore in Tamil Nadu alone.

Continue reading “Rajinikanth’s Kabali day 2 box office collection: Did the movie make Rs 250 crore on first day?”