Krita Posted October 5, 2007 Share Posted October 5, 2007 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 More sharing options...
Krita Posted October 5, 2007 Author Share Posted October 5, 2007 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); ?> Link to comment https://forums.phpfreaks.com/topic/71932-solved-call-mysql-procedure-from-php/#findComment-362345 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.