English 中文(简体)
发言稿
原标题:Prepared Statement not working in PHP

我试图用我方言执行一份准备发言,但声明从未执行过结果,也没有犯错误。 但执行询问通常奏效。

准备的疑问是:

SELECT * FROM games WHERE YEARweek(game_date)=?

经常没有准备的问询就是这种情况。

SELECT * FROM games WHERE YEARweek(game_date)= YEARweek(current_DATE) +1

任何想法为什么?

执行询问的守则在不同地点,但从短文来看似乎如此:

$WHERE_CLAUSE=  ;
        $first=true;
        if(isset($conditions[ conditions ])) {
            foreach($conditions[ conditions ] as $key=>$condition){
                    if(is_array($condition)){

                    } else {
                        if($first)
                            $WHERE_CLAUSE.=$key. =? ;
                        else 
                            $WHERE_CLAUSE.=  AND  .$key. =? ;

                        $input_data[$key]=$condition;
                        $first=false;
                    }
            }//end foreach

            if(!empty($WHERE_CLAUSE)){
                $query.= WHERE  .$WHERE_CLAUSE.   ;
            }
        }

        $result=PVDatabase::preparedSelect($query, $input_data);

public static function preparedQuery($query, $data, $formats =   ) {

    if (self::_hasAdapter(get_class(), __FUNCTION__))
        return self::_callAdapter(get_class(), __FUNCTION__, $query, $data, $formats);

    if (self::$dbtype == self::$mySQLConnection) {
        self::$link -> prepare($query);
        $count = 1;

        foreach ($data as $key => $value) {
            self::$link -> bindParam($count, $value);
            $count++;
        }//end foreach

        return self::$link -> execute();
    } else if (self::$dbtype == self::$postgreSQLConnection) {
        $result = pg_prepare(self::$link,   , $query);
        $result = pg_execute(self::$link,   , $data);
        return $result;
    } else if (self::$dbtype == self::$oracleConnection) {

    } else if (self::$dbtype == self::$msSQLConnection) {
        $stmt = sqlsrv_prepare(self::$link, $query, $data);
        return sqlsrv_execute($stmt);
    }

}//end preparedQuery
问题回答

由于你没有提供你重新使用的密码,我会怀疑你可能具有包括表达在内的价值。 不作评估,而是字面解释。

PDO必须放弃YEAR周(目前为DATE)+1部分。

而是:

$next_year = date( Y) + 1;

SELECT * FROM games WHERE YEARweek(game_date) = $next_year




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签