Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/200.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php ODBC无法使用参数筛选数据_Php_Android_Sql Server_Parameters_Odbc - Fatal编程技术网

Php ODBC无法使用参数筛选数据

Php ODBC无法使用参数筛选数据,php,android,sql-server,parameters,odbc,Php,Android,Sql Server,Parameters,Odbc,我使用ODBC通过web服务将我的Ms SQL Server数据库与我的Android应用程序连接起来。 我尝试使用PHP脚本获取数据,它运行平稳,可以从我的Ms SQL Server数据库获取所有数据。但当我试图在php脚本中使用WHERE子句获取一些数据并在查询中添加参数时,我得到了错误。以下是我的php脚本: <?php $dsn="myDSN"; $username="myUSername"; $password="myPassword"; $barcode = $_GET['b

我使用ODBC通过web服务将我的Ms SQL Server数据库与我的Android应用程序连接起来。 我尝试使用PHP脚本获取数据,它运行平稳,可以从我的Ms SQL Server数据库获取所有数据。但当我试图在php脚本中使用WHERE子句获取一些数据并在查询中添加参数时,我得到了错误。以下是我的php脚本:

<?php
$dsn="myDSN";
$username="myUSername";
$password="myPassword";

$barcode = $_GET['barcode'];

$koneksi = odbc_connect($dsn,$username,$password);

$sql = "select Barcode_ID, WO, ProductCategory, SubProductName, OrderType from T_MAIN 
    where Barcode_ID = $barcode";

$respon = array();

$tbl_main = odbc_exec($koneksi, $sql);

if (odbc_num_rows($tbl_main) > 0) {
    $respon["data_main"] = array();

    while ($row = odbc_fetch_array($tbl_main)) {
        $data_main = array();
        $data_main["barcodeID"] = $row["Barcode_ID"];
        $data_main["wo"] = $row["WO"];
        $data_main["product"] = $row["ProductCategory"];
        $data_main["subProduct"] = $row["SubProductName"];
        $data_main["ordertype"] = $row["OrderType"];

        array_push($respon["data_main"], $data_main);
    }
    $respon["sukses"] = 1;
    $respon["pesan"] = "Success!";

    echo json_encode($respon);
} else {
    $respon["gagal"] = 0;
    $respon["pesan"] = "Failed!";

    echo json_encode($respon);
}
odbc_close($koneksi);
?>
有人能帮我解决这个问题吗?
非常感谢您的建议。

使用带参数的查询,例如,从T_MAIN中选择Barcode_ID、WO、ProductCategory、SubProductName、OrderType,其中Barcode_ID=?然后将$barcode传递给execute方法。

谢谢您的建议。我已经解决了这个问题。警告显示“SQLExecDirect中的SQL状态07001”,当我搜索它时,我得到了“错误的参数编号”。因此,我尝试以下代码: $sql=从T_MAIN中选择条形码_ID、工单、产品类别、子产品名称、订单类型,其中条形码_ID='.int$Barcode';
而且它工作得很好

您需要在sql上替换字符串:其中Barcode_ID='$Barcode',我已经尝试过了,但不起作用,因为参数化查询中Bacode_ID是整数+1@TooCHANDRA考虑使用PDO而不是ODBC*来进行更多的OOP攻击。
Warning: odbc_exec(): SQL error: [Microsoft][ODBC SQL Server Driver]COUNT field incorrect or syntax error, SQL state 07001 in SQLExecDirect in C:\xampp\htdocs\myscripts\get_data_main.php on line 15

Warning: odbc_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\myscript\get_data_main.php on line 19 {"gagal":0,"pesan":"Gagal Mengakses Database!"}