0

I have triggered the stored procedure from php. I have passed the input parameters also as shown.

$id = 1;
$nameDetail = 'raj';
$result = mysqli_query('CALL InsertDetails($id,$nameDetail)');

But getting below error.

mysqli_query() expects at least 2 parameters, 1 given ...

Please suggest a solution.

sunil
  • 3,507
  • 18
  • 25
Gopal
  • 787
  • 3
  • 13
  • 19

2 Answers2

1

The issue is that you're not set the mysqli connection.please try this

$connection = mysqli_connect('localhost','username','password','db');
    $result = mysqli_query($connection,'CALL InsertDetails($id,$nameDetail)');
Shanu k k
  • 1,235
  • 2
  • 18
  • 43
  • Thanks for your reply. I have $id = 1; $nameDetail= 'test' ; $result = mysqli_query($connection,'CALL InsertDetails($id,$nameDetail)');. But the values not inserted in table. – Gopal Mar 07 '17 at 13:10
  • Yes it working. SP triggered. But values not stored in table. this is my SP CREATE PROCEDURE InsertDetails (id int, name varchar(100)) BEGIN Declare newvalue varchar(50) insert into student(id,Name) values(id,name); set newvalue = 'success'; select newvalue; END $$ – Gopal Mar 07 '17 at 13:14
  • wait let me check – Shanu k k Mar 07 '17 at 13:15
  • change this, `insert into student (id, Name) values (sid, sname);` – praveena Mar 07 '17 at 13:26
  • run your store procedure to check, – praveena Mar 07 '17 at 13:27
  • @praveena- agree – Shanu k k Mar 07 '17 at 13:28
  • @Gopal are you sure, your store procedure is execute successfully? – praveena Mar 08 '17 at 04:54
  • yes it was successfully executed. i can able to add value directly from SP . like CALL SP_name(1,'test'). But when i pass it from php it doesn't working,no errors found. – Gopal Mar 08 '17 at 04:56
  • any other SP write before this SP – praveena Mar 08 '17 at 04:59
  • no,first SP in this database.I have one table and one SP in database for testing purpose. – Gopal Mar 08 '17 at 04:59
  • $connection = mysqli_connect($servername, $username, $password, $dbname); $id = 2; $nameDetail = "venu"; $result = mysqli_query($connection,'CALL InsertDetails($id,$nameDetail)'); This is in PHP – Gopal Mar 08 '17 at 05:02
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/137510/discussion-between-praveena-and-gopal). – praveena Mar 08 '17 at 05:03
0

You need to pass in the connection as the first parameter:

// connect to DB
$connect = mysqli_connect("127.0.0.1", "my_user", "my_password", "my_db");

// run procedure
$result = mysqli_query($connect, 'CALL InsertDetails($id,$nameDetail)');
Niraj Shah
  • 15,087
  • 3
  • 41
  • 60