pdo

PHP PDO MySQL IN (?,?,?

空扰寡人 提交于 2020-02-20 05:32:46
问题 I want to write a MySQL statement like: SELECT * FROM someTable WHERE someId IN (value1, value2, value3, ...) The trick here is that I do not know ahead of time how many values there will be in the IN(). Obviously I know I can generate the query on the go with string manipulations, however since this will run in a loop, I was wondering if I could do it with a PDO PreparedStatement. Something like: $query = $PDO->prepare('SELECT * FROM someTable WHERE someId IN (:idList)'); $query->bindValue('

PHP PDO MySQL IN (?,?,?

最后都变了- 提交于 2020-02-20 05:32:00
问题 I want to write a MySQL statement like: SELECT * FROM someTable WHERE someId IN (value1, value2, value3, ...) The trick here is that I do not know ahead of time how many values there will be in the IN(). Obviously I know I can generate the query on the go with string manipulations, however since this will run in a loop, I was wondering if I could do it with a PDO PreparedStatement. Something like: $query = $PDO->prepare('SELECT * FROM someTable WHERE someId IN (:idList)'); $query->bindValue('

PDO statements with named parameters VS question mark parameters

时光毁灭记忆、已成空白 提交于 2020-02-15 22:50:28
问题 I have a class for database management, and one of my sub-classes (the one that defines a query) is defined like this (just a sample, many other functions are actually stripped for testing purposes): namespace Tests\SQL\Arguments { // SQL query class Query { public $attributes; // constructor for this object public function __construct() { if ($arguments = func_get_args()) { $this->attributes["query"] = current($arguments); if (sizeof($arguments) > 1) { $this->attributes["parameters"] = array

Trying Update Record with PDO

不羁岁月 提交于 2020-02-15 20:18:57
问题 I updated the question code I am still having issues no errors but does not update the record. also need to figure how to write in record # updated successfully. I am stuck on this update page. <?php error_reporting(E_ERROR | E_PARSE); require_once("db_connect.php"); $id = $_REQUEST['id']; $lanId = $_REQUEST['lanId']; $name= $_REQUEST['name']; $department = $_REQUEST['department']; $manager= $_REQUEST['manager']; $request = $_REQUEST['request']; $request_description = $_REQUEST['request

How can I get outside foreach loop value in this situation?

两盒软妹~` 提交于 2020-02-15 13:41:30
问题 I am trying to call all the value from a foreach loop from mysql data, and use there value input into another mysql select statement. Look at my code below. It only can gather one value. I was thinking to use the first foreach loop include the whole section, however, since foreach value is individual, and I need explode array for the PDO prepare. So, at last, I want to know a way to get all value from the outside foreach loop. Appreciate. //mysql connection code, remove because it is not

php+mysql基础增删查改

萝らか妹 提交于 2020-02-13 17:18:51
php连接数据库有MySQLi和PDO两种方法 以下以PDO为例 一、创建数据库表(students) 二、连接数据库(db.php) $dsn:数据库连接服务器,数据库名称 $db_user:登录数据库名称 $db_pass:登录数据库密码 1 <?php 2 $dsn="mysql:dbname=phpsql;host=localhost;charset=utf8"; 3 $db_user='root'; 4 $db_pass='123456'; 5 try{ 6 $pdo=new PDO($dsn,$db_user,$db_pass); 7 $pdo->exec('set names utf8'); 8 }catch(PDOException $e){ 9 echo '数据库连接失败'.$e->getMessage(); 10 } 11 ?> 三、显示数据列表(list.php) 1 <?php 2 require_once 'db.php'; 3 $sql = 'select * from students'; 4 $query = $pdo->query($sql); 5 echo "<table border='1'>"; 6 echo "<tr><td>id</td><td>number</td><td>name</td><td>操作</td><td>删除</td><

Installing PDO-drivers for PostgreSQL on Mac (using Zend for eclipse)

余生长醉 提交于 2020-02-10 02:09:04
问题 How can I get PDO to work on my mac (os x 10.5)? I'm using the built in php and php in Zend/Eclipse. Can't seem to find useful drivers for it at all. 回答1: I had to install the PDO_PGSQL driver recently on Leopard, and I ran across a multitude of problems. In my search for answers, I stumbled across this question. Now I have it successfully installed, and so, even though this question is quite old, I hope that what I've found can help others (like myself) who will undoubtedly run into similar

PDO count row values based on WHERE

≯℡__Kan透↙ 提交于 2020-02-06 09:07:21
问题 I looked over PHPDelusions website few times before asking this, as well as used Google but I still can't seem to get the code to work, or find a solution that remotely mirrors my question in general. I made a super simple PHP7 script for managing Receipts. The fields are simple. id (int 12), amount (varchar 8), category (int 2), date (date) The problem I'm facing is I'm trying to Count the Total Amount of money based on Categories . So let's say Category = 1 would count all Amounts with that

PDO连接数据库

半城伤御伤魂 提交于 2020-02-06 08:35:42
public function test1() { $pdo = new \PDO('mysql:host=127.0.0.1;dbname=phpframe;port=3306;charset=utf8','root','root'); print_r($pdo); } 测试查询一千条时间 echo microtime(); $pdo = new \PDO('mysql:host=127.0.0.1;dbname=phpframe;port=3306;charset=utf8','root','root'); for ($i=0;$i<10000;$i++){ $sql = "select * from test1"; $arr = $pdo->query($sql); $res = []; while($row = $arr->fetchObject()){ $res[]=$row; } } print_r($res); echo "<br>"; echo microtime(); 来源: CSDN 作者: 划水小老虎 链接: https://blog.csdn.net/weixin_43162776/article/details/103653023

PHP mysql: inserting data from an array

旧巷老猫 提交于 2020-02-06 07:28:29
问题 I'm having trouble extracting arrays to insert into the database. My form accepts multiple and dynamic number of inputs so I have the data in an array with inputs phonenos[] and phonetypes[]: <form name="add" action="" method="POST"> <input name="name" type="text" placeholder="Name"></input><br /> <input name="qty" type="text" placeholder="Qty"></input><br /> --> <input class="form-control required" name="phonenos[]" maxlength="14" type="text" placeholder="number..."><br> <select class="form