Php odbc_prepare/odbc_exec error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • stonicus
    New Member
    • May 2007
    • 1

    #1

    Php odbc_prepare/odbc_exec error

    [CODE=php]// Relevant parts of my DB class (from include file)
    class db_connection
    {
    function __construct()
    {
    $this->con = odbc_connect('S hippingData','n ame','pass');
    }
    private $con;

    function Prepare($query)
    {
    return odbc_prepare($t his->con, $query);
    }

    // Execute prepared queries...
    function Pexec($pq, $arr)
    {
    return odbc_exec($pq, $arr); // This is line 43 from below error
    }
    }


    // *** clip from my file ***

    $db = new db_connection;

    // Build the query...
    $query = "INSERT INTO Customers (CustomerID,Com panyName,Contac tName) VALUES (?,?,?);";

    // Prepare the query
    $pquery = $db->Prepare($query );

    // Build data array...
    $arr = array($customer _id,$company_na me,$contact_nam e);

    // Execute the prepared query... (dies in this func)
    $db->Pexec($pquer y, $arr); [/CODE]



    // The error I get
    Warning: odbc_exec(): supplied resource is not a valid ODBC-Link resource in E:\Web\ShipView \inc\db.phpinc on line 43


    What is causing me to get this error? I'm doing what every other example I've ever seen online is doing. Please help.
    Last edited by pbmods; May 17 '07, 04:40 PM. Reason: Changed code language. Thanks for using CODE tags!
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    According to PHP's manual, odbc_exec is supposed to prepare the query for you (as opposed to odbc_execute).

    Also, it doesn't look like odbc_exec takes an array for any of its arguments.

    Also also, if odbc_prepare fails to prepare the query, the return value won't be a valid resource identifier.

    I've never used ODBC before, but I hope this information (plus links) are useful.

    Comment

    Working...