此查询有效
SELECT id, username, password
FROM users
WHERE (email = ?)
LIMIT 1"
$stmt->bind_param('s', $email);
$stmt->execute();
$stmt->store_result();
这不是
SELECT id, username, password
FROM users
WHERE (email = ? || username = ?)
LIMIT 1"
需要同时使用电子邮件和用户名登录,而仅使用电子邮件无法登录
答案 0 :(得分:1)
使用OR代替||
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new Policy(),
);
}
}
class Policy extends StatefulWidget {
@override
_PolicyState createState() => _PolicyState();
}
class _PolicyState extends State<Policy> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
bottom: GradientTabBar(
colors: [Theme.of(context).primaryColor, Colors.green],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
tabBar: TabBar(
//indicatorColor: Colors.white,
tabs: [
Tab(icon: Icon(Icons.directions_car)),
Tab(icon: Icon(Icons.directions_transit)),
Tab(icon: Icon(Icons.directions_bike)),
],
),
),
title: Center(child: Text('POLICY')),
),
body: TabBarView(
children: [
Icon(Icons.directions_car),
Icon(Icons.directions_transit),
Icon(Icons.directions_bike),
],
),
),
),
);
}
}
class GradientTabBar extends StatefulWidget implements PreferredSizeWidget {
// Gradiente properties
final AlignmentGeometry begin;
final AlignmentGeometry end;
final List<Color> colors;
final TabBar tabBar;
GradientTabBar({
Key key,
@required this.colors,
this.begin = Alignment.centerLeft,
this.end = Alignment.centerRight,
this.tabBar,
}) : super(key: key);
@override
Size get preferredSize => tabBar.preferredSize;
@override
_GradientTabBarState createState() => _GradientTabBarState();
}
class _GradientTabBarState extends State<GradientTabBar> {
@override
Widget build(BuildContext context) {
return Stack(
children: <Widget>[
Container(
height: widget.preferredSize.height,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: widget.begin,
end: widget.end,
colors: widget.colors,
)),
),
widget.tabBar,
],
);
}
}
答案 1 :(得分:0)
声明参数时,您可以列出所有类型,然后列出其后的变量,例如下面的示例;
$sql = "SELECT id, username, password FROM users WHERE (email = ? OR username = ?) LIMIT 1"
$stmt->bind_param('ss', $email, $username);
此外,正如Shahnawaz所说,请使用OR代替||。