我在codeigniter
上使用了这个代码$this->db->trans_begin();
$this->db->query("SET @clientID = {$client_id}, @amount = {$amount}, @gameID = {$game_id}, @tableID = {$table_id}, @tableName = '{$table_name}', @usedBalanceID = NULL");
$this->db->query("SELECT availableBalance INTO @availableBalance FROM client WHERE clientID = @clientID");
SELECT availableBalance INTO @availableBalance 给我一个错误说
Severity: Warning --> mysqli_num_rows() expects parameter 1 to be mysqli_result;
system\database\drivers\mysqli\mysqli_result.php 37
但是使用返回没有错误
$this->db->query("SELECT @availableBalance := availableBalance FROM client WHERE clientID = @clientID");
任何人都可以解释为什么我在codeigniter上得到这个错误
但在laravel上使用代码时
SELECT availableBalance INTO @availableBalance FROM client WHERE clientID = @clientID
工作正常。
答案 0 :(得分:3)
$this->db->trans_begin();
$this->db->query("SET @clientID = {$client_id}, @amount = {$amount}, @gameID = {$game_id}, @tableID = {$table_id}, @tableName = '{$table_name}', @usedBalanceID = NULL");
$this->db->query("SELECT availableBalance INTO @availableBalance FROM client WHERE clientID = @clientID");
“SELECT @availableBalance:= availableBalance FROM client WHERE clientID = @clientID”;
我创建了一个示例sql脚本来解释我的答案。希望能帮助到你!干杯!
答案 1 :(得分:0)
SELECT INTO 声明selects data from one table and inserts it into a new table。您收到错误是因为查询$this->db->query("SELECT availableBalance INTO @availableBalance FROM client WHERE clientID = @clientID");
的SELECT部分正在返回false
,因此没有可以在表@availableBalance
中插入的值。
请检查client
表,因为SQL无法在availableBalance
列中找到clientID = @clientID
的任何值。