O
O
Optimus2015-11-11 19:09:29
PHP
Optimus, 2015-11-11 19:09:29

PDO php questions?

Small code, search by TIMESTAMP type field:

$a = '2007-08-09 01:00:00';
$b = '2007-08-09 08:00:00';
    
$st = $pdo->prepare('set profiling=1');
$st->execute();
    
$st = $pdo->prepare('SELECT `mytime` FROM `date` WHERE `mytime` BETWEEN a=:a AND b=:b ');
$st->bindParam(':a', $a, PDO::PARAM_STR);
$st->bindParam(':b', $b, PDO::PARAM_STR);
$st->execute();
$RES = $st->fetchAll();

Direct query to the view database
SELECT `mytime` FROM `date` WHERE `mytime` BETWEEN '2007-08-09 01:00:00' AND '2007-08-09 08:00:00'

works fine, but:
1) How to enable profiling set profiling=1 to see the query itself, you need to send a command in the same query somehow, profiling did not work for me like this
2) SQLSTATE[42000]: Syntax error on the query itself error or access violation: 1064 check the manual that corresponds to your MySQL server version for the right syntax to use near '='2007-08-09 01:00:00' AND b='2007-08-09 08:00:00'' at line 1
I can't understand what exactly he doesn't like in this request
3)Question on PDO::PARAM_STR I tried not to specify this parameter in other working requests, for example $b->bindParam(":email",$email); and everything works, then it is needed, not needed? It is clear that it specifies the data type (string, number, boolean, etc.)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2015-11-11
@melkij

1) dev.mysql.com/doc/refman/5.7/en/show-profile.html
2) between is written like this: dev.mysql.com/doc/refman/5.7/en/comparison-operato...
Compare with yours .
3) php.net/manual/en/pdostatement.bindparam.php , $data_type = PDO::PARAM_STR. Is there anything else that needs to be explained?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question