php - sql select query where date is greater then, including php variables -


already read other treads regarding matter, cant find answer includes php variables.

i want select first 100 new records after date of database. can't work.

$connstr =     'odbc:driver={microsoft access driver (*.mdb, *.accdb)};' .     'dbq='.$ini_project['general']['document_location'].';';  $dbh = new pdo($connstr); $dbh->setattribute(pdo::attr_errmode, pdo::errmode_exception);  $time = strtotime('6-8-2017 21:52:00');  $date = date('j-n-y h:i:s',$time);  $sql1  = "select top 100 * `$table_name $table_number` systeemtijd > `$date`";  $result = $dbh->query($sql1);  while($row = $result->fetch()) {       print_r($row); } 

i'm able select records field in table (where value > 200 example) not based on date column in table. tried without `` and:

$sql1  = "select top 100 * `$table_name $table_number` systeemtijd > date `$date`"; 

all give error:

fatal error: uncaught exception 'pdoexception' message 'sqlstate[42000]: syntax error or access violation: 0 [microsoft][odbc microsoft access driver] syntax error (missing operator) in query expression 'systeemtijd > 6-8-2017 21:52:00'. (sqlprepare[0] @ ext\pdo_odbc\odbc_driver.c:206)' in c:\bitnami\wampstack-5.6.30-1\apache2\htdocs\php7\databuilt\larissa_connector\data_uploader.php:65 stack trace: #0 c:\bitnami\wampstack-5.6.30-1\apache2\htdocs\php7\databuilt\larissa_connector\data_uploader.php(65): pdo->query('select top 100 ...') #1 {main} thrown in c:\bitnami\wampstack-5.6.30-1\apache2\htdocs\php7\databuilt\larissa_connector\data_uploader.php on line 65

passing variables not idea, have aware of how correctly escape them, try using pdo::prepare:

/* execute prepared statement passing array of values */ $sql = "select top 100 * $full_table_name    systeemtijd  > :date"; $sth = $dbh->prepare($sql); $sth->execute(array(':date' => $date); $red = $sth->fetchall(); 

http://php.net/manual/en/pdo.prepare.php


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -