php - 如何将 Laravel 查询生成器结果作为整数

标签 php laravel laravel-5 eloquent laravel-5.2

我正在使用 Laravel Query Builder 查询 MySQL 数据库,但它返回整数值作为字符串值。

我有以下查询。

$query = DB::table('store_products')->select('products.id', 'products.name', 'products.unit_type', 'products.price', 'products.image_path', 'products.is_popular', 'store_products.price AS store_price')
           ->join('products', 'products.id', '=', 'store_products.product_id')
           ->join('product_categories', 'product_categories.product_id', '=', 'store_products.product_id')
           ->where('store_products.store_id', $store_id)
           ->where('store_products.product_id', $product_id);

此处查询获取存在于 Store_Products 中的给定 store_id 的产品。

问题是,当我使用查询生成器时,它返回 id(这是产品的主键)作为 string。看起来转换有问题。

我该如何解决这个问题?

非常感谢您。

最佳答案

转换不是解决方案,而是解决问题的方法。您的实际问题是缺少 mysqlnd 插件。

检查是否安装了mysqlnd

$ sudo dpkg -l | grep 'mysqlnd'

如果没有安装,需要像这样安装(假设你有php5)

$ sudo apt-get install php5-mysqlnd

这些命令适用于 ubuntu。如果您有其他东西,只需将它们转换为适合您的操作系统即可。

关于php - 如何将 Laravel 查询生成器结果作为整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38819501/

相关文章:

php - 调用未定义的方法 ConsoleTVs\Charts\Builder::new() laravel

php - 如何在 Laravel 5 中构建模块化应用程序?

php - 在 MAMP 中导入数据库时​​出错

php - 一次运行多个查询

PHP - fatal error : Allowed memory size of 268435456 bytes exhausted

javascript - 为什么我在 Laravel 框架中收到此内部服务器错误?

php - 导致 sum() 到多个结果的分组表

php - 如何修复 'Class App\Http\Controllers\Productcontroller does not exist'

php - Laravel 路线未定义,但显然是

php - 从 Guzzle 响应访问特定属性?