PDA

View Full Version : سوال: نحوه ساخت stored procedure برای اضافه کردن رکورد به جدول



iradata
جمعه 29 اردیبهشت 1391, 10:40 صبح
سلام

من تازه با مفهموم stored procedure آشنا شده ام ، می خواستم بدونم که چه طور میشه که یک

stored procedure در دیتابیس تعریف کرد و از آن در php برای اضافه کردن رکورد به جدول استفاده کرد ؟؟؟

مثلا من در دیتابیس ام یک جدول به نام sUsers دارم که در آن فیلدهای :

fName
lName
Tell
Mobile
Email

روو دارم ، حالا چه طور میشه که در دیتابیس ام یک stored procedure برای این جدول تعریف کنم و از آن در php

برای اضافه کردن رکورد به جدول ام استفاده کنم . ( البته در سایت هم جستجو کردم اما نتیجه ای نداشت )

با تشکر

iradata
شنبه 30 اردیبهشت 1391, 11:32 صبح
کسی نیست به این سوال من جواب بده خیلی برام مهمه !!!!!!!!!!

behzadkhatari
شنبه 30 اردیبهشت 1391, 20:14 عصر
از چه بانکی استفاده میکنی؟

iradata
شنبه 30 اردیبهشت 1391, 20:35 عصر
از چه بانکی استفاده میکنی؟


DATABASE : MY SQL

farhadfery
یک شنبه 31 اردیبهشت 1391, 09:56 صبح
کسی نیست به این سوال من جواب بده خیلی برام مهمه !!!!!!!!!!
اگر مهم بود که سرچ می زنید, جواب را به دست می امد:چشمک:

ابتدا درباره استورپروسیجر:


MySQL Stored Procedures
A stored procedure is a named set of SQL commands stored in the MySQL server. Similar to
functions in PHP, stored procedures can receive parameters and return data. Stored procedures
in MySQL 5.1 follow the ANSI SQL 2003 specification. Their official documentation page is
http://www.mysql.org/doc/refman/5.1/en/stored-procedures.html.
You don’t need to use stored procedures if you want to perform database operations. You
can directly send SQL commands from an external application (such as a PHP script of your
TShirtShop application) to your MySQL database. When using stored procedures, instead of
passing the SQL code you want executed, you just call the stored procedure and the values for
any parameters it might have. Using stored procedures for data operations has the following
advantages:
Performance can be better, because MySQL generates an execution plan for the queries
in the stored procedure when it’s first executed, and then reuses the same plan on subsequent
executions of the procedure.
• Using stored procedures allows for better maintainability of the data access and manipulation
code, which is stored in a central place, and permits easier implementation of
the three-tier architecture (the database stored procedures forming the data tier).
• Security can be better controlled, because MySQL permits setting different security
permissions for each stored procedure.
• SQL queries created ad hoc in PHP code are more vulnerable to SQL injection attacks,
which is a major security threat (many Internet resources cover this security subject,
and you can find the most popular of them by Googling for “SQL injection attack”).
• This might be a matter of taste, but separating the SQL logic from the PHP code keeps
the PHP code cleaner and easier to manage; it simply looks better to execute a stored
procedure than to build SQL queries by joining strings in PHP.


The syntax for creating stored procedures is
DELIMITER $$
CREATE PROCEDURE <name>(<param1 type>, <param2 type> ... )
BEGIN
<code>
END$$
DELIMITER;
Note that the delimiter can be defined as something other than $$. The key is to define it
as something different than the default delimiter, the semicolon.
You can’t create a stored procedure if your database already has a procedure with the same
name. To remove an existing stored procedure, you use the DROP PROCEDURE command. To change
the body or parameters of an existing procedure, you need to delete it using DROP PROCEDURE and
create it again. MySQL supports a command named ALTER PROCEDURE, but unlike with other database
applications, it can’t be used to update the body or parameters of an existing procedure.منبع: کتاب Beginning PHP and MySQL E-Commerce

این هم یک مثال عملی:
http://www.joeyrivera.com/2009/using-mysql-stored-procedures-with-php-mysqlmysqlipdo/

sahar1982
یک شنبه 07 خرداد 1391, 14:43 عصر
اگه جواب نگرفتین من هم می تونم کمکتون کنم.