Jump to content

Recommended Posts

Hi guys,

 

I want to call stored procedure in mysql from php code - at first glance simple task, but I met huge problems. Maybe some of you could help me.

 

The code is

 

$sql = "call my_proc('".$_POST['a']."','".$_POST['b']."','".$_POST['c']."','".$_POST['d']."')";

mysql_query($sql);

 

But nothing happens - just like the lines are commented.

If i add echo $sql."<br>" - just to see the string generated, it looks ok -

 

"call my_proc('value_for_a','value_for_b','value_for_c','value_for_d')"

 

If I run thios sql from mysql prompt -

 

mysql>call my_proc('value_for_a','value_for_b','value_for_c','value_for_d');

 

it works, no problems. But from php code this execution is just skipped.

The connection to mysql is ok, before trying to call the procedure, I have some insert, updates, select on the database and they work pretty well. But calling procedure fails - actually nothing happens.

I get the feeling, that I am missing some generic point. Do I need any settings or what else?

 

The procedure my_proc was created as root in test database. The connection to the database is also as root, so it shouldn't be a permission problem. I browsed the forums here and found out some examples, but it is exactly what I do -

 

mysql_connect("localhost", "root", "password");

mysql_select_db("test");

$sql = "...";

mysql_query($sql);

 

 

If $sql is something like "insert into foo values('foo')" - it works.

If $sql is "call myproc..." - it doesn't, no errors returned.

 

Any ideas?

 

Thanks in advance,

Link to comment
https://forums.phpfreaks.com/topic/71932-solved-call-mysql-procedure-from-php/
Share on other sites

Hi,

 

I found out a solution -to use mysqli_query. Have no idea why mysql_query doesn't work ,but the following works

 

<?php

$dbcon = mysqli_connect("localhost", "user", "pass", "db");

$sql="call my_proc('foo1','foo2','foo3','foo4')";

mysqli_query($dbcon, $sql);

?>

 

The following doesn't work

 

<?php

mysql_connect("localhost", "user", "pass");

mysql_select_db("db");

$sql="call my_proc('foo1','foo2','foo3','foo4')";

mysql_query($sql);

?>

 

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.