Código
<?php $dbHost = 'localhost'; $dbName = 'invento'; $dbUser = 'root'; $dbPass = ''; try { $pdo = new PDO("mysql:host=$dbHost;dbname=$dbName","$dbUser", "$dbPass"); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch(Exception $e) { echo $e->getMessage(); } $title_out = $title[1]; $sql = "INSERT INTO prueba('title') VALUES ($title_out)"; $query = $pdo->prepare($sql); $result = $query->execute([ 'title' => $title_out ]); }
pero en la parte de insertar en la tabla prueba el valor me sale este error que dice ser un error de sintaxis en sql, quisiera saber que error estoy cometiendo:
Citar
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 ''title') VALUES (Google)' at line 1 in C:\xampp\htdocs\webcrawler\php-web-crawler\index.php:29 Stack trace: #0 C:\xampp\htdocs\webcrawler\php-web-crawler\index.php(29): PDOStatement->execute(Array) #1 {main} thrown in C:\xampp\htdocs\webcrawler\php-web-crawler\index.php on line 29
la linea 29 hace referencia al array que se pasa al execute()