我使用 Laravel Query Builder 查询 MySQL 数据库,但它返回整数值作为字符串值.
I'm using Laravel Query Builder to query MySQL database but it returns integer values as string values.
我有以下查询.
$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 中的 Product,用于给定 store_id.
Here the query gets Product which is existing in Store_Products for given store_id.
问题是,当我使用查询生成器时,它返回 id(这是产品的主键)作为 string.演员表好像有问题.
The problem is, it returns id (which is the Primary Key for Product) as string when I use Query Builder. Looks like there is something wrong with casts.
我该如何解决这个问题?
How can I solve this problem?
非常感谢您.
强制转换不是解决方案,而是解决问题的方法.您的实际问题是缺少 mysqlnd 插件.
Casting is not a solution but a workaround to the problem. Your actual problem is missing mysqlnd plugin.
检查mysqlnd是否像这样安装
$ sudo dpkg -l | grep 'mysqlnd'
如果没有安装,你需要像这样安装(假设你有php5)
If it's not installed, you need to install it like so (assuming you have php5)
$ sudo apt-get install php5-mysqlnd
这些命令适用于 ubuntu.如果您还有其他东西,只需将它们转换为您合适的操作系统即可.
These commands are for ubuntu. If you have something else, just convert them to your appropriate OS.
这篇关于如何将 Laravel Query Builder 结果作为整数获取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
PHP、MySQL PDOException 的死锁异常代码?Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死锁异常代码?)
PHP PDO MySQL 可滚动游标不起作用PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滚动游标不起作用)
PHP PDO ODBC 连接PHP PDO ODBC connection(PHP PDO ODBC 连接)
使用 PDO::FETCH_CLASS 和魔术方法Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔术方法)
php pdo 只从 mysql 获取一个值;等于变量的值php pdo get only one value from mysql; value that equals to variable(php pdo 只从 mysql 获取一个值;等于变量的值)
MSSQL PDO 找不到驱动程序MSSQL PDO could not find driver(MSSQL PDO 找不到驱动程序)