简体   繁体   中英

How to create a stored procedure in mysql

I have created the following stored procedure in mysql...

DELIMITER //
CREATE PROCEDURE GetMember(IN in_memberID int)
BEGIN
    SELECT *
    FROM Members
    WHERE MemberID = in_memberID;
END//



$result = mysql_query("CALL GetMember(".$memberID.")") or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
    echo $row['Name'] . "</br>";
}

But when I call it from php it returns all records in the Members table, what am I doing wrong?

EDIT: When I try to call the query within phpmyadmin I get this error

CALL GetMember(1);

#1312 - PROCEDURE myDb.GetMember can't return a result set in the given context

what version of PHP?

PHP 5.2.3 and PHP 5.2.4 have a bug with procedures: https://bugs.php.net/bug.php?id=42548

use Database_Name;

DELIMETER $$

DROP PROCEDURE IF EXISTS Proc$$
CREATE PROCEDURE Proc()
       BEGIN
               DECLARE x INT;
               SET x = 1;
               WHILE x <= 110000 DO
                   INSERT INTO Table_Name (word, mean) VALUES ('a', 'a mean');
                   SET x = x + 1;
               END WHILE;
       END$$

DELIMITER ;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM