Jump to content
Larry Ullman's Book Forums

Stored Procedures Not Working


Recommended Posts

I'm having a problem on one of the servers that I am using the stored procedures on. I have had luck with another (older) version of php and MySQL, but the following stored procedure won't work on the newer version. Any ideas:

 

 

 

CREATE PROCEDURE `addToCart`(uid CHAR(32), pid MEDIUMINT, sid VARCHAR(6), qty TINYINT)

BEGIN

DECLARE cid INT;

SELECT cartId INTO cid FROM carts

WHERE user_session_id=uid AND productsId=pid AND sizeId=sid;

IF cid > 0 THEN

UPDATE carts SET quantity=quantity+qty, date_modified=NOW() WHERE cartId=cid;

ELSE

INSERT INTO carts (user_session_id, productsId, sizeId, quantity) VALUES (uid, pid, sid, qty);

END IF;

END

 

The problem seems to be in user_session_id=uid and sizeId=sid. If I use sizeId='$sid', the sizeId works. But if I use user_session_id='$uid', it doesn't. This is the error I get if I use the code above:

 

Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation '='

An error occurred in script '/home/baertrax/public_html/eshop/cart.php' on line 87:

mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given

 

On one server that is working, I am using:

PHP Version 5.2.14

MYSQL 5.0.77

 

On another server where it is not working, I am using:

PHP Version 5.2.17

MySQL 5.1.56

Link to comment
Share on other sites

I found it, and it worked. I had to change the sid to CONVERT(sid USING utf8) COLLATE utf8_general_ci also. I want to build code that is reusable for other shopping carts. Will this work in the older version of MySQL that I am using, or will I have to have two different versions of the Stored Procedures?

Link to comment
Share on other sites

 Share

×
×
  • Create New...