Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > it.comp.www.php > #22082

Utilizzo di variabili in una query Mysql tramite PDO

From sap <sap@nospam.no>
Newsgroups it.comp.www.php
Subject Utilizzo di variabili in una query Mysql tramite PDO
Date 2018-05-25 15:59 +0200
Organization Aioe.org NNTP Server
Message-ID <pe94rl$8ig$1@gioia.aioe.org> (permalink)

Show all headers | View raw


Ciao a tutti,
non riesco a capire cosa sto sbagliando facendo quanto segue:

$query = "SET @tables = NULL;
             SET @schema = 'db_pippo';
             SET @pattern = '002_%';
             ";

$sth = $this->pdo->prepare($query);
$sth->execute();

Praticamente non arrivo neanche all'exevute ma ricevo questo errore:

"Fatal error: Uncaught exception 'PDOException' with message 
'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an 
error in your SQL syntax; check the manual that corresponds to your 
MariaDB server version for the right syntax to use near 'SET @schema = 
'db_pippo'; SET @pattern = '002_%'' at line 2' ..."




Dove $this->pdo รจ una istanza di PDO valida utilizzata senza problemi in 
altre parti del codice e definita come segue:

$opt = array(
                 PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
                 PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
                 PDO::ATTR_EMULATE_PREPARES => FALSE,
             );
             $dsn = 'mysql:host=' . HOST . ';dbname=' . DATABASE . 
';charset=' . CHARSET;
             $instance = new PDO($dsn, USER, PASSWORD, $opt);


Avete idea di cosa stia sbagliando?
Grazie in anticipo

Back to it.comp.www.php | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Utilizzo di variabili in una query Mysql tramite PDO sap <sap@nospam.no> - 2018-05-25 15:59 +0200
  Re: Utilizzo di variabili in una query Mysql tramite PDO fmigliori <fmigliori@gmail.com> - 2018-05-25 07:32 -0700
    Re: Utilizzo di variabili in una query Mysql tramite PDO sap <sap@nospam.no> - 2018-05-25 16:41 +0200
  Re: Utilizzo di variabili in una query Mysql tramite PDO Leonardo Serni <lserni@gmail.com> - 2018-05-25 20:05 +0200

csiph-web