我正在使用 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/