0

In my php application i need to call a stored procedure from MySQL

the procedure i have created is this.

DROP PROCEDURE IF EXISTS _proc.usp_hotel_rooms_mLoadByPrimaryKey;
CREATE PROCEDURE _proc.`usp_hotel_rooms_mLoadByPrimaryKey`(
_HTR_ID INT(11),
_HTR_TYPE_ID INT(11)
 )
 BEGIN

SELECT
    HTR_ID,
    HTR_NAME,
    HTR_TYPE_ID
FROM hotel_rooms_m
WHERE
    (HTR_ID = _HTR_ID AND HTR_TYPE_ID=_HTR_TYPE_ID)
  ;

 END;

I need to pass the parameters _HTR_ID and _HTR_TYPE_ID,so i tried it like this

<?php 
$con = mysql_connect("localhost","user","user")or die(mysql_error());
$db =  mysql_select_db("_proc") or die(mysql_error());
$par1 = "1";
$par2 = "2";
$dbh->query("CAST usp_hotel_rooms_mLoadByPrimaryKey($par1, $par2, @OutPut)");
 $dbh->query("SELECT @OutPut"); 
echo $dbh;
?>

this is the error i am getting Call to a member function query() on a non-object in D:\xampp\htdocs\_proc\index.php on line

4

3 回答 3

1

您似乎混淆了一些样式:也不mysql_connect返回mysql_select_db对象,并且mysql_*不推荐使用所有函数。您的$dbh->query陈述似乎建议使用 mysqli 或 PDO 进行数据库连接。

您可能希望使用 mysqli 或 PDO 打开一个连接,然后将其分配给您的$dbh变量。

于 2012-10-01T16:58:19.560 回答
1

你的代码在这里

    <?php 
    $dbh = new PDO('mysql:host=localhost;dbname=_proc', "user", "user");
    $par1 = "1";
    $par2 = "2";
    $dbh->query("CAST usp_hotel_rooms_mLoadByPrimaryKey($par1, $par2, @OutPut)");
    $dbh->query("SELECT @OutPut"); 
    echo $dbh;
    ?>
于 2013-02-15T00:17:09.677 回答
1

You have to use

your connection string like this using mysqli

$mysqli = new mysqli(  "HOST", "USR", "PWD", "DBNAME" );

Here is the link for tutors Mysql stored procedures with php

于 2012-10-01T17:02:43.710 回答