call stored procedure in mysql from php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
krita
Forum Newbie
Posts: 2
Joined: Fri Oct 05, 2007 3:08 am

call stored procedure in mysql from php

Post by krita »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


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

Code: Select all

$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 -

Code: Select all

"call my_proc('value_for_a','value_for_b','value_for_c','value_for_d')"
If I run thios sql from mysql prompt -

Code: Select all

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 -

Code: Select all

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,


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
krita
Forum Newbie
Posts: 2
Joined: Fri Oct 05, 2007 3:08 am

Post by krita »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi,

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

Code: Select all

<?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

Code: Select all

<?php
mysql_connect("localhost", "user", "pass");
mysql_select_db("db");
$sql="call my_proc('foo1','foo2','foo3','foo4')";
mysql_query($sql);
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The only thing I can think of is the basic MySQL library was originally built for 4.x and lower versions of MySQL. Updating a dll/so brings its API up to support 5.x. MySQLi is MySQL 5 ready from the start.
Post Reply