pdo

PHP Bootstrap 4 navigation menu with sub-menu's

风格不统一 提交于 2020-01-11 04:10:10
问题 ORIGINAL POST I want to create a navigation menu in PHP with Bootstrap 4. Problem is that one of the <li> 's is not right (the one from dropdown , it doesn't become a dropdown but just a normal nav-item ). This code works alright if you want to make a normal menu with <ul> and <li> but with bootstrap you need to have a nav-item dropdown on the <li> of id 2 named Dropdown . How would I do this? I hope this is enough information. This is the array(): array (size=3) 0 => array (size=5) 0 =>

How do I store a BIGINT in MySQL using PDO?

泄露秘密 提交于 2020-01-11 02:27:06
问题 I know this question has been asked more than once here, but I couldn't find a solution. We are using a database where we are storing the facebook id as a BIGINT(20). create table users( fb_id bigint(20) NOT NULL, user_name varchar(30) NOT NULL, CONSTRAINT uk_name unique (user_name), CONSTRAINT pk_fb_id primary key (fb_id) )ENGINE=INNODB; But the PDO engine of PHP can insert only the max integer value of PHP, i.e. 2147483647. $stmt->bindParam(':fb_id', $this->fb_id, PDO::PARAM_INT); This, I

测试

一世执手 提交于 2020-01-10 15:24:00
getAttribute()设置数据库连接属性 先确认可以得到那些属性,然后在设置一下 1表示默认情况下自动提交时开启的 0代表错误模式默认的是静默模式 getAttribute()设置数据库连接属性 先确认可以得到那些属性,然后在设置一下 1表示默认情况下自动提交时开启的 0代表错误模式默认的是静默模式 那么,我们可以通过setAttribute()设置自动提交的属性为0 那么,我们可以设置哪些属性呢?? 常用的是前三个: 第一个是是否自动提交PDO::ATTR_AUTOCOMMIT,自动提交为1,否则为0 第二个是错误处理模式PDO::ATTR_ERRMODE,静默模式为0 第三个是字段名称是否大小写转换PDO::ATTR_CASE,不开启大小写为0 注意:如果部分属性是没有的,表示数据库驱动不支持这种属性 数据库的一些链接属性可以放在$options中 quote()方法防止SQL注入 一定要过滤用户输入的数据 ———————————————— 版权声明:本文为CSDN博主「cpongo6666」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。 原文链接:https://test66.blog.csdn.net/article/details/95944804 getAttribute()设置数据库连接属性 先确认可以得到那些属性

PDOException not being caught?

我们两清 提交于 2020-01-10 05:41:05
问题 I'm getting the following error in PHP: Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'localhost' (10061)' in C:\xampp\htdocs\project\Service\Database.class.php:26 Stack trace: #0 C:\xampp\htdocs\project\Service\Database.class.php(26): PDO->__construct('mysql:host=loca...', 'root', '', Array) #1 C:\xampp\htdocs\project\Service\Database.class.php(54): Service\Database::initialize() #2 C:\xampp\htdocs\project\index.php(15):

Suppressing PDO Warnings

馋奶兔 提交于 2020-01-10 05:09:05
问题 I'm trying to display a server status, based upon whether the database can be connected to or not. With the old school mysql_connect() and mysqli_connect() it was easy. I'm trying to stay modern, so I'm using PDO, but I can't figure out how-to suppress the default warning. From what I can tell, you need to use the getMessage() function for it to print the PDO warning, but I'm not using it. Here's my code: 8 $dbstatus = 1; 9 try { 10 $db = new PDO($dbms . ':host=' . $dbhost . ';port=' .

How to fetch 2 times in MYSQL PDO without FETCHALL

醉酒当歌 提交于 2020-01-10 05:06:26
问题 I have this sample query: $STH = $DBH->query("SELECT id FROM table"); I want to get the first row and then loop and display all rows. So I use the following to get the first row: $STH->setFetchMode(PDO::FETCH_ASSOC); $first_row = $STH->fetch(); $first_row = $first_row['id']; I use while loop to display all rows again: while ($list = $STH->fetch()) { $id = $list['id']; echo $id; } Now the while skips the first row and I want it to be displayed. Is there an equivalent to mysql_data_seek to

How to retrieve the id of the last inserted row when using PDO in PHP?

天大地大妈咪最大 提交于 2020-01-09 12:08:32
问题 Example: I insert a row into the DB with this, using PHP's built in PDO: $sql = "INSERT INTO mytable (name, ok) VALUES ('john', '1')"; $this->dbh->exec($sql); I need the id of that row. How could I get that? 回答1: If the id is an auto_increment , you can use PDO::lastInsertId : Returns the ID of the last inserted row, or the last value from a sequence object, depending on the underlying driver. So, in your case, something like this should do the trick : $lastId = $this->dbh->lastInsertId(); 来源

How to retrieve the id of the last inserted row when using PDO in PHP?

醉酒当歌 提交于 2020-01-09 12:07:10
问题 Example: I insert a row into the DB with this, using PHP's built in PDO: $sql = "INSERT INTO mytable (name, ok) VALUES ('john', '1')"; $this->dbh->exec($sql); I need the id of that row. How could I get that? 回答1: If the id is an auto_increment , you can use PDO::lastInsertId : Returns the ID of the last inserted row, or the last value from a sequence object, depending on the underlying driver. So, in your case, something like this should do the trick : $lastId = $this->dbh->lastInsertId(); 来源

How to retrieve the id of the last inserted row when using PDO in PHP?

馋奶兔 提交于 2020-01-09 12:06:20
问题 Example: I insert a row into the DB with this, using PHP's built in PDO: $sql = "INSERT INTO mytable (name, ok) VALUES ('john', '1')"; $this->dbh->exec($sql); I need the id of that row. How could I get that? 回答1: If the id is an auto_increment , you can use PDO::lastInsertId : Returns the ID of the last inserted row, or the last value from a sequence object, depending on the underlying driver. So, in your case, something like this should do the trick : $lastId = $this->dbh->lastInsertId(); 来源

Datetime NOW PHP mysql (+ PDO variant)

柔情痞子 提交于 2020-01-09 09:49:28
问题 Thanks for looking. All helpful answers/comments are up voted. In php, you can use NOW() like this: mysql_query("INSERT INTO tablename (id, value, time_created) VALUES ('{$id}', '{$value}', NOW())"); How can I do the same thing in PDO. When I bind like this, I get an error: $stmt->bindParam(':time_added', NOW(), PDO::PARAM_STR); Is it the PDO:PARAM_STR? 回答1: Because nobody has explicitly answered the question, I'll add the correct answer for the sake of completeness. $stmt = $pdoDb->prepare(