By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,590 Members | 663 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,590 IT Pros & Developers. It's quick & easy.

Get the value returned by a function (mysql)

P: 2
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
Share this Question
Share on Google+
2 Replies


Rabbit
Expert Mod 10K+
P: 12,359
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

P: 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

Post your reply

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