pdo

How to return max(id) in pdo

喜你入骨 提交于 2020-04-30 07:42:21
问题 I am trying to return the last id and increment it to put in the value attribute. I can make it work with old mysql but not with the PDO. I am learning (I think) PDO but it is not making sense. Below is the code. <td><label for="invNum"></label>Invoice</td> <?php $stmt = $dbconn->prepare("SELECT max(invId) FROM invoices"); $stmt->execute(); $invNum = $stmt->fetch(); /* mysql_select_db("customers", $dbconn); $result = mysql_query("SELECT max(invId) FROM invoices"); if (!$result) { die('Could

Mysql - Couldn't connect unknown database 'databasename' error

你说的曾经没有我的故事 提交于 2020-04-26 06:09:24
问题 I am using PDO to connect to mySql database. I am not able to connect to any database that I create although I can connect to already created databases( already created by default). I am using wamp server. <?php try{ $dbh=new PDO("mysql:host=localhost;dbname=mydata","root",""); }catch(Exception $e){ die("ERROR: Couldn't connect. {$e->getMessage()}"); } ?> If i substitute mydata with mysql which is previously created database in wamp server, then the code works perfectly. The only problem is

PDO prepare with question marks doesn't work with numbers [duplicate]

时光怂恿深爱的人放手 提交于 2020-04-11 17:11:33
问题 This question already has answers here : Reference — frequently asked questions about PDO (3 answers) Closed 6 years ago . I have this : $pdo = new PDO('mysql:host=localhost;dbname=mydb', 'user', 'pass'); $max = 10; $min = 0; $q = $_GET['q']; $result = $pdo->prepare("SELECT * FROM fruits WHERE name LIKE ? LIMIT ?, ?"); $result->execute(array('%'.$q.'%', $min, $max)); However it doesn't work (returns nothing) while when I replace LIMIT by LIMIT 0, 10 and remove $min and $max from the array it

PDO prepare with question marks doesn't work with numbers [duplicate]

ⅰ亾dé卋堺 提交于 2020-04-11 17:11:09
问题 This question already has answers here : Reference — frequently asked questions about PDO (3 answers) Closed 6 years ago . I have this : $pdo = new PDO('mysql:host=localhost;dbname=mydb', 'user', 'pass'); $max = 10; $min = 0; $q = $_GET['q']; $result = $pdo->prepare("SELECT * FROM fruits WHERE name LIKE ? LIMIT ?, ?"); $result->execute(array('%'.$q.'%', $min, $max)); However it doesn't work (returns nothing) while when I replace LIMIT by LIMIT 0, 10 and remove $min and $max from the array it

PDO prepare with question marks doesn't work with numbers [duplicate]

ぃ、小莉子 提交于 2020-04-11 17:11:05
问题 This question already has answers here : Reference — frequently asked questions about PDO (3 answers) Closed 6 years ago . I have this : $pdo = new PDO('mysql:host=localhost;dbname=mydb', 'user', 'pass'); $max = 10; $min = 0; $q = $_GET['q']; $result = $pdo->prepare("SELECT * FROM fruits WHERE name LIKE ? LIMIT ?, ?"); $result->execute(array('%'.$q.'%', $min, $max)); However it doesn't work (returns nothing) while when I replace LIMIT by LIMIT 0, 10 and remove $min and $max from the array it

Install / Configure SQL Server PDO driver for PHP docker image

假装没事ソ 提交于 2020-04-11 03:52:27
问题 I have a simple docker file, as follows: FROM php:7.2-apache COPY src/ /var/www/html/ Normally to install drivers for Mongo or MySQL connectivity I would do so by adding something like the below to the dockerfile: docker-php-ext-install mongo On this occasion I want to connect my php application to a SQL Server database, and I understand the best way to do this for php 7.x is by using the PDO driver, however I am unfamiliar with how to do configure this in the dockerfile. I've tried doing a

PDO update table using array

喜欢而已 提交于 2020-04-07 09:35:06
问题 I'm learning and new in PDO. The usage of array in PDO causes difficulty for me. I'm developing simple web application using PDO syntax. Everything is going on smoothly, but I can't update multiple values from single submit button. HTML FORM <td> <input type="number" name="roll[]" value="<?php echo $roll?>"> </td> <td> <input type="text" name="name[]" value="<?php echo $name?>"> <td> I can print data. if(isset($_POST['submit'])){ $name = $_POST['name']; $roll = $_POST['roll']; foreach( $roll

PDO基础应用之异常处理

◇◆丶佛笑我妖孽 提交于 2020-03-29 13:32:41
思考:PDOException可以捕捉到异常,也有其他模式,那么在实际开发的时候我们到底是使用PDO的那种错误模式呢? 引入:其实PDO之所以提供了这么多模式,就是要使用人员根据实际情况来选择模式,如果一个项目中,需要我们去控制项目bug,那么就适合使用异常模式来进行处理 PDOException异常处理【掌握】 定义:PDOException 是PDO从Excetion继承的一个用于处理PDO错误的异常类,一般如果做一套扩展,都会从Exception类继承实现一套明确的错误机制(错误来自哪里) 1.要使用PDOException异常处理,需要设定PDO的错误模式为异常模式,在PDO中可以通过两种模式来实现异常模式设定 在初始化PDO对象的时候,利用第四个参数来设定 在初始化PDO之后,利用PDO::setAttrinute()方法来修改错误模式 <?php //初始化PDO时设定错误模式 $drivers=array( PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCPTION ); $link=new PDO('mysql:host=localhost;port=3306;dbname=senven;charset=utf8','root','root',$drivers); //初始化之后设置异常模式 $pdo=new PDO('mysql:host

pdo中的预处理语法

早过忘川 提交于 2020-03-26 17:32:20
3 月,跳不动了?>>> 什么叫预处理语法 就是,为了“重复执行”多条结构类似的sql语句,而将该sql语句的形式“进行预先处理”(编译); 该sql语句的“形式”中,含有“未给定的数据项”。 然后,到正式执行的时候,只要给定相应的形式上的“数据项”,就可以更快速方便执行。 比如(有两种预定义语法): 语法1: $sql = “select * from tab where id = ? “; //这里这个“?”就是未给定的数据项;这里通常叫做“占位符” //也可以是多个问好。 语法2: $sql = “select * from tab where id = :v1 and name = :v2 “; //这里这个“:v1”和 “:v2” 就是未给定的数据项;通常这里叫做“命名参数”; 怎么使用? 分3步: 1,对含预处理语法的sql语句进行“预处理”: $stmt = $pdo->prepare($sql ); // 2, 对上述预处理的结果对象($stmt)的未赋值数据,进行赋值: $stmt->bindValue( 数据项1, 值1); $stmt->bindValue( 数据项2, 值2); 。。。。。。 3, 执行执行: $stmt->execute(); 这样之后,该sql语句就算正式完成! <?php header ( 'content-type:text/html

Linux下PHP扩展pdo_mysql

北慕城南 提交于 2020-03-26 10:26:17
PHP扩展的安装方式通常分为两种: 1. 随同PHP编译 2. 生成单独的.so文件 PHP编译安装之后可能需求扩展一些组件比如pdo_mysql,gd什么的,好在php5中有一个phpize工具可以帮助我们轻松的扩展PHP而不需要重新编译PHP,笔者在扩展pdo_mysql却遇了一些问题,特与大家分享: 情况描述: phpinfo()显示 pdo support enabled pdo drivers sqlite2, sqlite 没有支持mysql 最初按时下面的方法来扩展【 注意下面这个方法没有成功 】: 在php的原码安装包里,进入到etc/pdo_mysql里。假设你的php是安装在/www/bin/php里的。执行/www/bin/php/bin/phpize ./configure –with-php-config=/usr/local/php/bin/php-config 经过configure就可以make了 make make install 注意pdo_mysql的全路径,我的是: /usr/local/php/lib/php/extensions/debug-non-zts-20060613/pdo_mysql.so 然后在/usr/local/lib/php.ini 加上一句: extension=/usr/local/php/lib/php