繁体   English   中英

PHP DB2 odbc_exec()错误

[英]PHP DB2 odbc_exec() errors

我正在为价格检查器设备编写一个小型Web应用程序,但停留在尝试通过PHP中的DB2数据库使用ODBC检索数据的过程中。

我收到这些错误(主要关注粗体/第一个警告):

警告:odbc_exec():在第43行的C:\\ xampp \\ htdocs \\ db2 \\ findme.php中,提供的资源不是有效的ODBC-Link资源。

警告:odbc_fetch_row()期望参数1为资源,在第46行的C:\\ xampp \\ htdocs \\ db2 \\ findme.php中给出布尔值

警告:odbc_num_rows()期望参数1为资源,第53行的C:\\ xampp \\ htdocs \\ db2 \\ findme.php中给出的字符串

下面是我的代码:

<html>
<head><title>Searching for item...</title>
</head>
<body bgcolor=#ffffff>

<?php
$username = "admin";
$password = "admin";
$hostname = "localhost";
$port = "50000";
$database="HLDB";

$conn_string = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=$database;"."HOSTNAME=$hostname;PORT=$port;PROTOCOL=TCPIP;UID=$username;PWD=$password";

$conn = odbc_connect($conn_string, '', '');

echo "<h2>Search Results:</h2><p>";

//Retrieve input from find field on previous page and store in a variable
$find = $_POST['find'];

echo "User searched for: " . $find . "<br><br>";

//If they did not enter a search term we give them an error
if ($find == "")
{
echo "<p>Please scan for an item!";
exit;
}

// Otherwise we connect to our Database
if ($conn){
    echo "Connection succeeded. \n";
    odbc_close($conn);
}
else{
    echo "Connection failed. \n";
}

//Now we search for our search term, in the field the user specified
$sql = "SELECT * FROM NULLID.ITEMS WHERE 'ITEM NO.' LIKE '%$find%'";

$rs=odbc_exec($conn,$sql);

//fetch tha data from the database 
while(odbc_fetch_row($rs))
{
    //display the data
    echo odbc_result($rs, "Description 1"), "\n";
}

//This counts the number or results - and if there wasn't any it gives them a little message explaining that
$anymatches=odbc_num_rows($sql);
if ($anymatches == 0)
{
echo "Sorry, but we are unable to find this product...<br><br>";
}

//And we remind them what they searched for
echo "<b>Searched For:</b> " .$find;
?> 


</body>
</html>

您是否尝试保持连接打开? 您的代码显示了odbc_close($ conn); 验证成功连接后。 您应该删除该行以保持连接打开,否则$ conn对于后续的odbc_exec()无效

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM