Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8709813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:27:45+00:00 2026-06-13T04:27:45+00:00

This query ` delimiter $$ CREATE DEFINER=`root`@`localhost` FUNCTION `calculatePrice`(cheese VARCHAR(50), meat VARCHAR(50), veg VARCHAR(50))

  • 0

This query `

delimiter $$

CREATE DEFINER=`root`@`localhost` FUNCTION `calculatePrice`(cheese VARCHAR(50), meat VARCHAR(50), veg VARCHAR(50)) RETURNS decimal(10,0)
    DETERMINISTIC
BEGIN
DECLARE price DECIMAL;
SET price = (SELECT  SUM(x.Price) 
    FROM
    (
        SELECT `priceFactor` AS Price FROM `tblCheese` WHERE `cheeseName` = cheese
        UNION ALL 
        SELECT `priceFactor` AS Price FROM `tblMeat` WHERE `meatName` = meat 
        UNION ALL 
        SELECT `priceFactor` AS Price FROM `tblVeggie` WHERE `veggieName` = veg
    ) x );
RETURN price;
END$$

`

is returning the mathematically-correct answer when called from the MySQL command-line client, but incorrect for any other program or when called from PHP (it’s returning 3 there, no matter what parameters are passed.) See below:
Identical query, identical parameters, different results

The calling statement, in case it’s blurry, is SELECT calculatePrice(‘colby’, ‘sausage’, ‘black beans’);

I’ve never seen this weirdness before. It’s all going off of the same copy of MySQL, etc.

Edit to add: phpMyAdmin also yields the correct answer to the query.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:27:46+00:00Added an answer on June 13, 2026 at 4:27 am

    I can tell you how that went.

    MySQL has shipped for the longest time with latin1_swedish_ce as default character set for practically everything. Now, you usually take care of the character set when creating databases, so the danger there is minimal.

    However, transferring the data over a line needs an encoding, and interpreting the data on the user end needs interpretation, too. So there are settings for that as well. And the standard character sets for MySQL tools are (as they are from the same company) latin1_swedish.

    Whether this will be a problem for a query highly depends on all the data that the query runs over. Also, when using constant strings in your query, they are interpreted much the same way as data coming from the database to your client.

    Therefor, character encoding is often the problem, and it was here as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've this function: DROP FUNCTION IF EXISTS find_linkid; DELIMITER // CREATE FUNCTION `find_linkid`(pc1 VARCHAR(50)
I've used the following split function: CREATE FUNCTION dbo.Splitfn(@String varchar(8000), @Delimiter char(1)) returns @temptable
I have created a function in my database using this query: CREATE FUNCTION dbo.fnSplit(
I have a MySQL function that looks like this: delimiter # create function activate_user
I have this code DELIMITER $$ DROP FUNCTION IF EXISTS `GetNextID` $$ CREATE FUNCTION
I have an error while executing this query: CREATE TRIGGER insert_Topics BEFORE INSERT ON
DELIMITER || CREATE FUNCTION InsertEvent (IN iPatientMonitoringId BIGINT, IN iTypeId SMALLINT(6), IN iChannelId SMALLINT(6),
Look at this code: DELIMITER $$ DROP TRIGGER IF EXISTS `after_product_insert` $$ CREATE TRIGGER
I'm trying to create the following SQL query (as in, this is an example
Modifed. DROP FUNCTION IF EXISTS PersonName; DELIMITER |; CREATE FUNCTION PersonName( personID SMALLINT )

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.