pdo

Understanding PDO Prepared Statements and Binding Parameters

别说谁变了你拦得住时间么 提交于 2020-01-14 06:15:14
问题 From experience and also having been told constantly the benefits of using prepared statements and binding my parameters, I have constantly used those two techniques in my code, however I would like to understand exactly the purpose of each of those two techiques: From my understanding of prepared statements: $sql = "SELECT * FROM myTable WHERE id = ".$id; $stmt = $conn->prepare($sql); $stmt->execute(); The previous code should create a sort of a buffer in the database with the query I

using doctrine 2 with SQL Server

坚强是说给别人听的谎言 提交于 2020-01-14 06:14:13
问题 I need to migrate an existing project, built on the current beta of doctrine 2, from mysql to SQL Server. I have complete control of the SQL Server. In the DBAL Folder of Doctrine there already is a PDOMsSql driver, but I can't figure out, how to use it. (there is still no documentation) Doctrine also offers two other ways, I could maybe use: driverClass: Specifies a custom driver implementation if no 'driver' is specified. This allows the use of custom drivers that are not part of the

PDO, $_GET, and SELECTing from MySQL Database

岁酱吖の 提交于 2020-01-14 06:01:06
问题 So I'm working on a PHP Pastebin-esque project on my freetime to learn PHP and server management, and I've run into a LOT of issues, and I haven't been able to solve them. I decided to restart from sratch on my own with the information I've gathered so far, and threw this code together. <?php require 'connection.php'; $getid = $_GET["id"]; $sql = 'SELECT paste FROM pasteinfo WHERE id=:id'; $stmt = $con->prepare($sql); $stmt->bind_param(':id', trim($_GET["id"], PDO::PARAM_INT)); $stmt->execute

PDO - query giving no results

亡梦爱人 提交于 2020-01-14 05:18:09
问题 This is my prepared statment. SELECT `id`, `title`, `image`, `discount`, `price`, `new_price`, `img_url` FROM `deals` WHERE `active`="1" AND `category`=:ctid AND `img_url`!="" AND `Brands`=:p1 ORDER BY `order`, `id` ASC LIMIT 0, 12; This is the array that i am using in bindParam . Array ( [:ctid] => 1 [:p1] => Apple ) Here's the PHP code: $sql = 'SELECT `id`, `title`, `image`, `discount`, `price`, `new_price`, `img_url` FROM `deals` WHERE `active`="1" AND `category`=:ctid AND `img_url`!=""

Bind IS NULL or NULL when using PHP PDO and MySql

社会主义新天地 提交于 2020-01-14 04:28:12
问题 How can I bind NULL in the following scenario. No matter what I do, I can't get it to work. if ($type == 1) { $self = 'NULL'; $parent = 'NULL'; } $findThis = $conn->prepare('select count(id) as exists from table where id = :id and self = :self and parent = :parent'; $findThis->execute(array( ":id" => $id, ":self" => $self, ":parent" => $parent )); 回答1: UPDATE. By an by I have learned that all can be done in one query $sql = 'select 1 from table where id = ? and self <=> ? and parent <=> ?';

how to access input box values that contains comma separated values and insert into database

喜欢而已 提交于 2020-01-14 03:36:05
问题 This is My PHP code till now I tried <?php include_once("../include/connClass.php"); $db = new Database(); $conn = $db->getConnection(); if(isset($_POST["save"])) { $date = $_POST["txtDate1"]; } $date = $_POST["txtDate1"]; $service = $_POST["txtService1"]; $charge = $_POST["txtCharge1"]; $amount = $_POST["txtAmount1"]; $unit = $_POST["txtUnit1"]; $total = $_POST["txtTotal1"]; for ($i = 0; $i <= count($date); $i++) { try { $sql = $conn->prepare("INSERT INTO backup_master (backup_date, backup

PDO : prepare with bindvalue and like %

两盒软妹~` 提交于 2020-01-14 01:38:32
问题 I've looked over an hour on various website but I couldn't solve my problem. So here is the code that works: $animes = array(); $q = $this->_db->query('SELECT id, nom, nom_id FROM animes WHERE nom LIKE "%code%"'); while ($data = $q->fetch(PDO::FETCH_ASSOC)) { $animes[] = new Anime($data); } return $animes; And here is the one that doesn't work : $animes = array(); $q = $this->_db->prepare('SELECT id, nom, nom_id FROM animes WHERE nom LIKE :n'); $q->bindValue(':n',"%code%",PDO::PARAM_STR);

Correct way to write PDO update statements

情到浓时终转凉″ 提交于 2020-01-13 20:30:07
问题 Is this the correct way to write a PDO update statement? I based it off a tutorial I saw online but it doesn't seem to be doing anything at all when fired by AJAX (even though the AJAX request is being logged as successful in the console, no update is made to the database): $duedate = $_POST["duedate"]; $status = $_POST["status"]; $id = $_POST["id"]; $sql = "UPDATE pm_schedule SET duedate=?, status=? WHERE id=?"; $q = $pdo->prepare($sql); $q->execute(array($duedate,$status,$id)); 回答1: Yes, it

PDOException with message 'SQLSTATE[] (null) (severity 0)'

六眼飞鱼酱① 提交于 2020-01-13 16:55:31
问题 The server I am working on is running php 5.5 and it has FreeTDS dblib installed. php -v returns; PHP 5.5.0-dev (cli) (built: Oct 23 2012 15:41:58) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies The build is as such; Configure Command => './configure' '--with-apxs2=/usr/bin/apxs2' '--enable-track-vars' '--with-mssql' '--with-png-dir=/usr' '--with-jpeg-dir=/usr' '--with-zlib-dir=/usr' '--enable-ftp' '--with-gd' '--enable-freetype-4bit

使用默认模式-PDO::ERRMODE_SILENT

混江龙づ霸主 提交于 2020-01-13 16:14:49
在PDO中捕获 SQL 语句错误有三种方案可以选择,根据自己的开发项目和实际情况选择适合的方案来捕获SQL 语句的错误! 大理石平台价格表 那么我们在前的文章《PDO中执行SQL语句的三种方法》中介绍PDO中执行SQL语句的三种方法,以及在以前的三篇文章《PDO中获取结果集之fetch()方法详解》《PDO中获取结果集之fetchAll()方法详解》《PDO中获取结果集之fetchColumn()方法详解》中介绍了关于PDO中获取结果集的三种方法,那么我们今天给大家介绍关于PDO中捕获SQL语句中的错误的几种方法~! 今天给大家介绍使用默认模式-PDO::ERRMODE_SILENT。 在默认模式中设置 PDOStatement 对象的 errorCode数据,但是不进行其他的任何操作。 下面我们用实例给大家介绍默认模式-PDO::ERRMODE_SILENT的具体使用,具体步骤如下: 首先创建一个php文件,添加表单,将表单元素提交到本页面,通过 PDO 连接MySQL数据库,通过预处理语句的 prepare()和execute()方法执行 INSERT 添加操作,向数据表中添加数据,并且设置 PDOStatement对象的 errorCode属性,来检测代码中的错误,具体代码如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19