title: Fatal error: Uncaught PDOException: SQLSTATE[42000] in DELETE
body: <p><code>Fatal error: Uncaught PDOException: 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 '' at line 1</code>.</p>
  <p>I know there have been a lot of question with the same topic, but I am just not able to find my mistake. The mistake is in &quot;DELETE&quot;</p>
  <p>This is my code in conexion.php</p>
  <pre><code>?php
  
  class conexion{
      private $servidor = &quot;localhost&quot;;
      private $usuario = &quot;root&quot;;
      private $password = &quot;&quot;;
      private $conexion;
  
      public function __construct(){
  
          try{
              $this-&gt; conexion = new PDO(&quot;mysql:host = $this-&gt;servidor;dbname=proyectos&quot;,$this-&gt;usuario,$this-&gt;password);
              $this-&gt; conexion -&gt; setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
          }catch(PDOException $e){
              return &quot;falla de conexión&quot;.$e;
          }
      }
  
      public function ejecutar($sql){       
          $this -&gt; conexion -&gt; exec($sql);
          return $this -&gt; conexion -&gt; lastInsertId();
      }
      public function consultar($sql){
          $sentencia = $this -&gt; conexion -&gt; prepare($sql);
          $sentencia -&gt; execute();
          return $sentencia -&gt; fetchAll();
      }
  }
  </code></pre>
  <p>?&gt;</p>
  <p>This is my code in: galeria.php</p>
  <pre><code>&lt;?php
  
  if($_GET){
      //&quot;DELETE FROM proyecto WHERE `proyecto`.`id` = 1&quot;
  
      $id = $_GET['borrar'];
      $obj_conexion = new conexion();
      $sql = &quot;DELETE FROM proyecto WHERE id =&quot;.$id;
      $obj_conexion -&gt; ejecutar($sql);
  }
  $obj_conexion = new conexion();
  $proyectos = $obj_conexion -&gt; consultar(&quot;SELECT * FROM  `proyecto`&quot;);
  //print_r($proyectos);
  </code></pre>
  <p>?&gt;
  <br></p>
  <pre><code>&lt;tbody&gt;
      &lt;?php foreach($proyectos as $proyecto){ ?&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;?php echo $proyecto['id']; ?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?php echo $proyecto['nombre']; ?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?php echo $proyecto['imagen']; ?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?php echo $proyecto['descripcion']; ?&gt;&lt;/td&gt;
          &lt;td&gt; &lt;a name=&quot;&quot; id=&quot;&quot; class=&quot;btn btn-danger&quot; href=&quot;?borrar= &lt;?php $proyecto['id']; ?&gt;&quot;&gt;Eliminar&lt;/a&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;?php } ?&gt;
  &lt;/tbody&gt;
  </code></pre>