Php mysqli绑定参数错误? [英] Php mysqli Binding Parameter Error?

查看:59
本文介绍了Php mysqli绑定参数错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  $ cookie_FromVal  = '  2015-10-28 12:00:00 am'; 
$ cookie_ToVal = ' 2015-10- 28:00:00 am';

$ conn = new mysqli($ hostname,$ username,$ password) ,$数据库);
// 检查连接
if ($ conn-> connect_error){
die( 连接失败:。$ conn-> connect_error);
}
echo 已连接成功;
// 获取数据并存储在json数组中

$ stmt = $ conn-> prepare( SELECT用户名,地址,国家/地区FROM Users WHERE UpdatedDate BETWEEN?AND?);

echo Binding1 。$ cookie_FromVal。 ;
echo Binding2 。$ cookie_ToVal。 ;
$ stmt-> bind_param(' 是',$ cookie_FromVal,$ cookie_ToVal);

$ stmt-> execute();
$ result = $ stmt-> get_result();
$ users = null ;
if ($ result-> num_rows> 0){
while ($ row = $ result-> fetch_assoc()){
$ usersToday [] = array(
' 用户名' => $ row [' 用户名'],
' address' => $ row [ ' address'],
' 县' => $ row [' country']
);
$ users = $ usersToday ;
}
} 其他 {
echo 0 results;
}
mysqli_free_result($ result);
$ conn-> close();
header( Content-type:application / json);
echo {\data \\ \\: .json_encode($ users)。 };





您有以上源代码,用于从mysql获取用户详细信息

特定范围的UpdatedDate datetime FromDate和toDate



如果我将$ cookie_FromVal和$ cookie_ToVal设置为不同的

datetime,上面的代码工作正常而没有错误,

但如果我将两个值设置为相等则返回所有

数据库内的行...

如果我设置$ cookie_FromVal = $ cookie_ToVal ='2015-10-28 12:00:00 am'

它返回的所有行都是'2015-10-28 12:00:00 am'

并且也等于'2015-10-28 12:00:00 am'而不管查询。



仅当数据库的日期值小于或等于给定日期时才会出现这种情况

且日期$ cookie_FromVal和$ cookie_ToVal相等

伙计们请帮我解决这个问题。



谢谢

Sreeyush

解决方案

cookie_FromVal = ' 2015-10-28 12:00:00 am';


cookie_ToVal = ' 2015-10-28 12:00:00 am';


conn = new mysqli的(

$cookie_FromVal = '2015-10-28 12:00:00am';
$cookie_ToVal = '2015-10-28 12:00:00am';

$conn = new mysqli($hostname,$username,$password,$database);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
echo "Connected successfully";
// get data and store in a json array

$stmt = $conn->prepare("SELECT username,address,country FROM Users WHERE UpdatedDate BETWEEN ? AND ?");

echo "Binding1 " .$cookie_FromVal . "";
echo "Binding2 " .$cookie_ToVal . "";
$stmt->bind_param('is', $cookie_FromVal, $cookie_ToVal);

$stmt->execute();
$result = $stmt->get_result();
$users = null;
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
    $usersToday[] = array(
        'username' => $row['username'],
        'address' => $row['address'],
        'county' => $row['country']       
      );
	$users =  $usersToday;
}
} else {
    echo "0 results";
}
mysqli_free_result($result);
$conn->close();
header("Content-type: application/json"); 
echo "{\"data\":" .json_encode($users). "}";



Hi have the above source code for getting user details from mysql for
particular range of UpdatedDate datetime FromDate and toDate

If I set $cookie_FromVal and $cookie_ToVal as different
datetime the above code works fine without an error ,
but If I set both values as equal it returns all the
rows inside the database...
say if I set $cookie_FromVal=$cookie_ToVal='2015-10-28 12:00:00am'
it returns all rows which is lessthan '2015-10-28 12:00:00am'
and also which is equal to '2015-10-28 12:00:00am' irrespective of query.

This occurs only if database have date values lesser or equal to given dates
and both the dates $cookie_FromVal and $cookie_ToVal are equal
Guys please help me to sort out this issue.

Thanks
Sreeyush

解决方案

cookie_FromVal = '2015-10-28 12:00:00am';


cookie_ToVal = '2015-10-28 12:00:00am';


conn = new mysqli(


这篇关于Php mysqli绑定参数错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆