pdo

How to print a while() loop in PDO [closed]

笑着哭i 提交于 2019-12-25 06:36:50
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I have a database table with 4 columns: Name , Comment , Star , Status . I want to display all the records of the table on a single page. Here is my query: $sth = $this->db->prepare("SELECT * FROM comment WHERE status = 1"); $sth->setFetchMode(PDO::FETCH_ASSOC); $sth->execute(); $reviews = array(); while($row =

SQLSTATE[42000]: Syntax error or access violation - PDO “GRANT” prepared statement [duplicate]

巧了我就是萌 提交于 2019-12-25 06:32:05
问题 This question already has answers here : Reference — frequently asked questions about PDO (3 answers) Closed 5 years ago . I am trying to create a prepared statement using PDO that will allow me to create mysql users using data collected from a form. When i run the command though, i get the error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''select

PDO prepared statement - syntax and sanitization

对着背影说爱祢 提交于 2019-12-25 06:29:59
问题 I'm trying to update my database with the following: $fields = array( 'titulo', 'tipo_produto', 'quantidade_peso', 'unidade_de_venda', 'unidades_por_caixa', 'caixas_piso', 'pisos_palete', 'tipo_palete', 'unidades_palete', 'caixas_palete', 'uni_diametro', 'uni_largura', 'uni_profundidade', 'uni_altura', 'caixa_largura', 'caixa_profundidade', 'caixa_altura', 'altura_palete', 'volume_unidade', 'volume_caixa', 'volume_palete', 'peso_caixa', 'peso_palete' ); $sql = 'UPDATE ficha_item SET '.implode

MYSQL_ATTR_INIT_COMMAND error

Deadly 提交于 2019-12-25 06:05:11
问题 I'm new to Zend Framework and I'm learning how to create an application following the steps in the framework.zend webpages. I have a problem with the global.php page. my global.php is: return array( 'db' => array( 'driver' => 'Pdo', 'dsn' => 'mysql:dbname=zf2tutorial;host=127.0.0.1;charset=utf8', 'driver_options' => array( PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'" ), ), 'service_manager' => array( 'factories' => array( 'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter

MYSQL_ATTR_INIT_COMMAND error

独自空忆成欢 提交于 2019-12-25 06:05:06
问题 I'm new to Zend Framework and I'm learning how to create an application following the steps in the framework.zend webpages. I have a problem with the global.php page. my global.php is: return array( 'db' => array( 'driver' => 'Pdo', 'dsn' => 'mysql:dbname=zf2tutorial;host=127.0.0.1;charset=utf8', 'driver_options' => array( PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'" ), ), 'service_manager' => array( 'factories' => array( 'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter

Calling a key of a json_decoded array return NULL

丶灬走出姿态 提交于 2019-12-25 05:33:12
问题 I am struggling to understand why certain cases that specific way to access the key in PDO works while when I tried myself, it didn't. For example, $sth = $this->dbh->prepare("UPDATE eq_question SET ". $user->field ."=? WHERE questID=?"); this PDO accessed an array's key (which was in a javascript object then posted and json_decoded in PHP) with $user->field , but when I tried to simulate the decoded array and use var_dump ($user->field) , I will receive NULL . Can anyone tell me why is it

PDO use quote with an array

不羁的心 提交于 2019-12-25 05:23:24
问题 I'm new in PDO $sFields = "'".implode("', '", $fields)."'"; $sColumns = implode(", ", $columns); $sql = "INSERT INTO $table ($sColumns) VALUES ($sFields)"; What is the shortest way to use PDO::quote on each value I want to insert. I tried $fields = array_map('$bdd->quote', $fields); but it returns: Warning: array_map() expects parameter 1 to be a valid callback, function '$bdd->quote' not found or invalid function name 回答1: There is other way than concat sql string. $sColumns = implode(", ",

PDO __constructs expects at least 1 parameter, 0 given

烂漫一生 提交于 2019-12-25 05:03:31
问题 I have database class and constructor function this: <?php class Connection { private $PDO; function __construct() { $username = 'root'; $password = 'password'; $PDO = new PDO('mysql:dbname=PROOV;host=localhost', $username, $password); return $this->PDO; } } ?> And the other class that extends it: <?php //$query = 'SELECT part_description FROM SparePartRequests LIMIT 100'; include_once 'connection.php'; class Proov extends PDO { public function returnRows() { $sth = $this->prepare('SELECT

PHP stream_get_contents() behaves strangely reading an LOB from a database

牧云@^-^@ 提交于 2019-12-25 04:58:06
问题 I have 2 records in a table with similar CLOB data. Each of those are parsed from a query and then read into a string by php in a loop against the returned PDO::FETCH_ASSOC it looks something like this after the query returns the results: ID | NAME | DESCRIPTION | LOB_DEFINITION 4409 foo blah blah long text that is stored in a lob ~ 5k characters 4410 foobar blah blah some other long text stored in a lob ~ 5k characters My problem is that once I start looping through this and reading contents

How use an array/implode in the SELECT query PDO

安稳与你 提交于 2019-12-25 04:53:17
问题 i have a function that returns user data from the database. But I want to return only the selected row, for instance username, so i created an array for that, giving the option to echo $userdata['anything'] . see the code: $session_user_id = $_SESSION['user_id']; $user_data = user_data($session_user_id, 'user_id', 'username', 'password', 'first_name', 'last_name'); } and function user_data($user_id){ $pdo = new PDO("mysql:host=localhost;dbname=MYDATABASE;", "MYUSERNAME", "MYPASSWORD"); $data