473,395 Members | 1,452 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Get the value returned by a function (mysql)

Hi. I am trying to get the value my function (mysql) returns in my php program and I couldnt't till now: PLEASE can anybody help me? Thanks a lot from now.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.   $link = mysqli_connect('localhost', 'myuser', 'mypass', 'database') 
  4. or die ('Error connecting to mysql: ' . mysqli_error($link));
  5.  
  6.   $mires=0;
  7.   $result = mysqli_query($link, "select addtable('r',$mires)");
  8.    while ($row = mysqli_fetch_assoc($result))
  9.   {
  10.    $myoutput= $row['myvalue'];
  11.     echo $myoutput;
  12.   }
  13. ?>
In my database
Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE `mytable` (
  2.   `idta` INTEGER(11) NOT NULL AUTO_INCREMENT,
  3.   `nom` VARCHAR(20) COLLATE latin1_swedish_ci DEFAULT NULL,
  4.   PRIMARY KEY (`idta`)
  5.  
  6. )ENGINE=InnoDB
  7. AUTO_INCREMENT=15 CHARACTER SET 'latin1' COLLATE 'latin1_swedish_ci';
  8.  
The Function addtable in mysql is:
Expand|Select|Wrap|Line Numbers
  1. BEGIN
  2. DECLARE xid integer;
  3. INSERT INTO mytable ( nom)
  4. SELECT pin AS Expr1;                   
  5. set xid=LAST_INSERT_ID();
  6. return myvalue;
  7. END
THANKS A LOT!!

update:
I made a mistake, I put
$result = mysqli_query($link, "select addtable('r',$mires)");
instead of
$result = mysqli_query($link, "select addtable('r')");
but this was not my problem, that is, I am still in trouble with this.
Oct 3 '11 #1
2 1966
Rabbit
12,516 Expert Mod 8TB
Please use code tags when posting code.

In your PHP code, you're trying to access a field named 'myvalue' from your SQL. However, in your SQL, you don't have any fields called 'myvalue'. You have one field in your SQL, and that field has no name because you didn't give it an alias.

In your function code, you're returning a variable called 'myvalue'. But you never declare that variable nor do you ever assign it a value. So it's not going to return anything anyways.
Oct 3 '11 #2
The solution, here

Expand|Select|Wrap|Line Numbers
  1. $success = mysqli_query($conexion, "call AltaModinmue(0,0,$tipoinmue,@ide)");
  2.  
  3.     if (!$success){
  4.         printf("mensaje Error: %s\n", mysqli_error($conexion));
  5.     }
  6.     else{ 
  7.         $retorno = mysqli_query($conexion,"select @ide");
  8.         $fila = mysqli_fetch_array($retorno);
  9.         $clave = $fila[0];
Oct 10 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: peter | last post by:
I am trying to truncate some Chinese Text returned from MySQL. If I use the substr function, then the last one or two chinese words would appear as symbols as opposed to the word it should be...
2
by: ritchie | last post by:
Hi, Just wanted to ask if anybody has any idea what i'm doing wrong. I have a function which edits a linked list. It works fine. I pass in a pointer to the list plus the value of the item to...
9
by: noor.fatma | last post by:
Hi all, if I declare a function as one returning int and do not return anything from the function ,what will it return? for example. the following function returns the value of sum correctly....
9
by: DanielJohnson | last post by:
I am wondering where does the value returned by main goes. Suppoes main returns some number say 42, where is it stored. Supposed a shell script call a C program and the program returns the value...
7
by: ScripterSam | last post by:
Hello Freinds, I have a funtion to call from setTimeout function which will return some value.. I mean I need to get the value, the function called from the setTimeout function returns... Please...
1
by: servo | last post by:
I created a user "test1" (which then got the username "debscrof_test1" from CPanel), a password for the user "test2", and then added the user to a new database "testdb" with all priviliges Then a...
1
by: rag84dec | last post by:
Hi , I have a const member function which returns a protected member of a class.Like this class A { protected: int Number; public: int Get_Number (void) const { return(Number); } };
2
by: sbettadpur | last post by:
hello I am getting following error while connecting to mysql through php Warning: mysql_connect() : Access denied for user: 'pds@localhost' (Using password: YES) Actually I hosted one...
2
by: rahullko05 | last post by:
i am stuck in the problem, where after user logs in successfuly, i take him to the login thanks page. now on that page i need to retain the login name. I am not sure how to this. i have written a...
5
by: lisles | last post by:
i have a page funtion.php which hs the function to connect to the db /* Mysql Connection */ function connect(){ global $db_server,$db_user,$db_pass,$db;//Global Values from the config.php...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.