Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从常规sql转换后,laravel sql查询不起作用_Php_Sql_Laravel_Laravel 4 - Fatal编程技术网

Php 从常规sql转换后,laravel sql查询不起作用

Php 从常规sql转换后,laravel sql查询不起作用,php,sql,laravel,laravel-4,Php,Sql,Laravel,Laravel 4,我想知道您是否可以查看3个sql查询,然后是无法工作的转换后的联接查询。我不断得到一个未定义的索引错误-不确定我做错了什么 请注意,$db\u table\u prefix=app\u没什么大不了的。 $db->sql\u escape=mysql\u real\u escape\u string(删除的b/c laravel自己进行转义) 1: 旧的: 新的: 2: 旧的: 新的: 三,。 旧的: 新的: 谢谢 我假设您是从其他一些代码中获得未定义的索引,这些代码使用您在这里发布的3个查询的返

我想知道您是否可以查看3个sql查询,然后是无法工作的转换后的联接查询。我不断得到一个未定义的索引错误-不确定我做错了什么

请注意,$db\u table\u prefix=app\u没什么大不了的。

$db->sql\u escape=mysql\u real\u escape\u string(删除的b/c laravel自己进行转义) 1: 旧的:

新的:

2: 旧的:

新的:

三,。 旧的:

新的:


谢谢

我假设您是从其他一些代码中获得未定义的索引,这些代码使用您在这里发布的3个查询的返回。您可以发布处理返回值的代码吗?似乎您试图以错误的方式访问返回的数据,而不是查询本身。我在一个类中使用了这些查询,并使用$functionvar['Group_Name']调用了它们。它应该可以工作,因为它返回一个数组。但是数组结构可能与您期望的不同。尝试将其转储以检查返回的数组是否与您期望的匹配?
$sql = "SELECT ".$db_table_prefix."Users.Group_ID, 
       ".$db_table_prefix."Groups.* 
       FROM ".$db_table_prefix."Users
       INNER JOIN ".$db_table_prefix."Groups ON ".$db_table_prefix."Users.Group_ID = ".$db_table_prefix."Groups.Group_ID 
       WHERE
       User_ID  = '".$db->sql_escape($this->user_id)."'";
return (array)DB::table('app_Users')
  ->select('app_Users.Group_ID')
  ->join('app_Groups', 'app_Users.Group_ID', '=', 'app_Groups.Group_ID')
  ->where('User_ID', '=', $this->user_id)
  ->first();
$sql = "SELECT ".$db_table_prefix."Users.Group_ID, 
        ".$db_table_prefix."Groups.* FROM ".$db_table_prefix."Users 
        INNER JOIN ".$db_table_prefix."Groups ON ".$db_table_prefix."Users.Group_ID = ".$db_table_prefix."Groups.Group_ID
        WHERE User_ID  = '".$db->sql_escape($this->user_id)."'
        AND
        ".$db_table_prefix."Users.Group_ID = '".$db->sql_escape($db->sql_escape($id))."'
        LIMIT 1
        ";
return (bool)DB::table('app_Users')
  ->select('app_Users.Group_ID')
  ->join('app_Groups', 'app_Users.Group_ID', '=', 'app_Groups.Group_ID')
  ->where('User_ID', '=', $this->user_id)
  ->where('app_Users.Group_ID', '=', $id)
  ->first();
$sql = "SELECT ".$db_table_prefix."Users.Group_ID, 
       ".$db_table_prefix."Groups.* 
       FROM ".$db_table_prefix."Users
       INNER JOIN ".$db_table_prefix."Groups ON ".$db_table_prefix."Users.Group_ID = ".$db_table_prefix."Groups.Group_ID 
       WHERE
       User_ID  = '".$db->sql_escape($userId)."'";
return (array) DB::table('app_Users')
  ->select('app_Users.Group_ID')
  ->join('app_Groups', 'app_Users.Group_ID', '=', 'app_Groups.Group_ID')
  ->where('User_ID', '=', $userId)
  ->first();