php - 在 PHP 中从远程数据库检索数据时出错

标签 php android mysql

I Get the errors as shown at the table while I trying to retrieve data.

如何解决表中所示的问题?当我尝试从数据库检索数据时发生这种情况。在我的java代码中,我尝试调用的json数组为null。

db_connect.php

<?php 
class DB_CONNECT{
// constructor
function __construct() {
    // connecting to database
    $this->connect();
}

// destructor
function __destruct() {
    // closing db connection
    $this->close();
}

/**
 * Function to connect with database
 */
function connect() {
    // import database connection variables
    require_once __DIR__ . '/db_config.php';

    // Connecting to mysql database
    $con = mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD) or die(mysql_error());

    // Selecing database
    $db = mysql_select_db(DB_DATABASE) or die(mysql_error()) or die(mysql_error());

    // returing connection cursor
    return $con;
}

/**
 * Function to close db connection
 */
function close() {
    // closing db connection
    mysql_close();
}


}

?>'

retEqp.php

<?php


/*
 * Following code will list all the products
 */

// array for JSON response
$response = array();

// include db connect class
require_once __DIR__ . '/db_connect.php';

// connecting to db
$db = new DB_CONNECT();

// get all products from products table
$result = mysql_query("SELECT *FROM facilities_equipments where item_Type='Equipment'") or die(mysql_error());

// check for empty result
if (mysql_num_rows($result) > 0) {
    // looping through all results
    // products node
    $response["equipments"] = array();

    while ($row = mysql_fetch_array($result)) {
        // temp user array
        $equipment = array();
        $equipment["item_ID"] = $row["item_ID"];
        $equipment["item_Name"] = $row["item_Name"];



        // push single product into final response array
        array_push($response["equipments"], $equipment);
    }
    // success
    $response["success"] = 1;

    // echoing JSON response
        echo json_encode($response);
    } else {
        // no products found
        $response["success"] = 0;
        $response["message"] = "No products found";


    // echo no users JSON
    echo json_encode($response);
    }
    ?>

最佳答案

替换您的代码

$con =  mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD) or die(mysql_error());

$con =  mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD) or die(mysql_error());

关闭所有已弃用的警告,包括来自 mysql_* 的警告:

error_reporting(E_ALL ^ E_DEPRECATED);

关于php - 在 PHP 中从远程数据库检索数据时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28913471/

相关文章:

php - 带有 session 的网页,用于对 Android 应用程序进行身份验证

php - 将列值从 Select 查询传递到另一个查询以在 PHP 中插入

android - 在android中的onClick按钮中选择和取消选择

Android 小部件大小

javascript - 在 php 和 html 中重写/屏蔽 url 地址

php - 强制网络浏览器播放文件而不是下载

java - 检查用户决定是否正确

java - 从具有外部数据库连接的 spring 项目构建 jar 文件

javascript - 动态表ajax替换页面中所有行/表单中的元素

php - 在 MySQL 表行中使用加法?