pdo

How to set up and inject multiple PDO database connections in slim 4?

折月煮酒 提交于 2020-01-24 09:37:06
问题 I could make an instance of PDO and inject it successfully. I defined the PDO::class directly and injected it in the constructor with __construct(PDO $pdo) . I would need something like PDO1::class and PDO2::class to inject it like follows: __construct(PDO1 $pdo1, PDO2 $pdo2) but that obviously doesn't work. There is only one PDO class and what I need to do is 2 instances of it with different database credentials. What is the best way to do it? I set up one definition of a database via PDO

PHP / MySQL Conceptual Database 'Sync' question

断了今生、忘了曾经 提交于 2020-01-24 07:30:28
问题 I am working on a PHP class implementing PDO to sync a local database's table with a remote one. The Question I am looking for some ideas / methods / suggestions on how to implement a 'backup' feature to my 'syncing' process. The ideas is : Before the actual insert of the data takes place, I do a full wipe of the local table's data. Time is not a factor so I figure this is the cleanest and simplest solution and I wont have to worry about checking for differences in the data and all that jazz.

centos7 开启sqlsrv扩展

天涯浪子 提交于 2020-01-24 02:49:54
参考:https://www.cnblogs.com/rrrena/p/8832190.html pdo_sqlsrv扩展下载地址:https://pecl.php.net/package/pdo_sqlsrv sqlsrv扩展地址: https://pecl.php.net/package/sqlsrv 1.加入微软的源 curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssqlrelease.repo   2.安装驱动(三个都要装上,缺一不可) yum install msodbcsql mssql-tools unixODBC-devel    (安装其他扩展,只需要从第3步开始就行,event扩展地址:https://pecl.php.net/package/event) 3.下载pdo_sqlsrv扩展包 http://pecl.php.net/package/pdo_sqlsrv 如上图,复制下载链接 wget 下载 解压 命令:tar -zxvf pdo_sqlsrv-5.3.0.tgz 命令:cd pdo_sqlserv-5.3.0 // 进入此目录 说明:寻找你的phpize 我的是用的宝塔面板,每个人的phpize可能位置不一样,具体的根据phpize来

A more efficient way of binding a big insert or update?

荒凉一梦 提交于 2020-01-23 16:47:14
问题 Ok so im new to binding, here is some code that works. I learned this format from a tutorial but i imagine there is more efficent ways to do it. In my example there is 4 names but in reality i will be doing a lot of inserts and updates in a project im working on that will have 20 or so fields. I like this approach for its clarity but obviously when your talking 20 fields or more it does take a lot of real estate. Lets look at my code first. Here are the functions it uses: // prepare the

PHP - PDO fetch resultset with column as index and column as value

放肆的年华 提交于 2020-01-23 11:44:32
问题 Hi i have a table with the following structure +-------------+------+ | date | price| +-------------+------+ | 2014-02-19 | 34 | | 2014-02-20 | 30 | | 2014-02-21 | 28 | +-------------+------+ At present PDO::FETCH_ASSOC returns an associative array with format like this array( 0=> array( "date" => 2014-02-19 , "price" => 34 ), 1=> array( "date" => 2014-02-20 , "price" => 30 ), 2=> array( "date" => 2014-02-21 , "price"=> 28 ) ) This is alright by the way, but i was looking for a way to return

PHP - PDO fetch resultset with column as index and column as value

假如想象 提交于 2020-01-23 11:41:34
问题 Hi i have a table with the following structure +-------------+------+ | date | price| +-------------+------+ | 2014-02-19 | 34 | | 2014-02-20 | 30 | | 2014-02-21 | 28 | +-------------+------+ At present PDO::FETCH_ASSOC returns an associative array with format like this array( 0=> array( "date" => 2014-02-19 , "price" => 34 ), 1=> array( "date" => 2014-02-20 , "price" => 30 ), 2=> array( "date" => 2014-02-21 , "price"=> 28 ) ) This is alright by the way, but i was looking for a way to return

Insert password hash using PDO Prepared Statements

无人久伴 提交于 2020-01-23 09:45:12
问题 In a basic mysql insert you are able to set a password variable 'PASSWORD($password)' but this breaks a PDO statement. How do you hash the password while using pdo::prepare and pdo::execute? $sql= "INSERT INTO contractors (userid, password, name) VALUES ('$userid', '$pass1', '$name')"; $result = $dbh->prepare($sql); $count = $result->execute(); Echo $count."<br>"; I am such a n00b, a simple registration page has taken me two days. Kindergarten answers are welcomed. thanks, 回答1: If you wanted

PHP PDO: Unable to connect, Invalid catalog name

笑着哭i 提交于 2020-01-23 05:16:52
问题 I am trying to set up a new site on my hosting (Host route if it matters) but i keep getting this error when i try using PDO (first PDO site im trying): Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected' in /home/kennyi81/public_html/gamersite/login.php:36 Stack trace: #0 /home/kennyi81/public_html/gamersite/login.php(36): PDOStatement->execute() #1 {main} thrown in /home/kennyi81/public_html/gamersite/login.php on

Uncaught exception 'PDOException' with message 'SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect string value

荒凉一梦 提交于 2020-01-23 02:33:30
问题 This is the error I am getting. PDOException: Uncaught exception 'PDOException' with message 'SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect string value: '\xF0\x9F\x98\xB3' for column 'string' at row 1' I know the problem here. The column table is using utf8 . The utf8 encoding cannot store 4 byte characters so it errors. A way to get around this could be to use utf8mb4 instead. My question instead is about the error message. We are using MariaDB. Why does it say "Invalid datetime

Differences between using ? and :param in prepare statement

给你一囗甜甜゛ 提交于 2020-01-22 09:51:05
问题 Let's say I want to select records where Id = 30 . Prepared statements allow two ways of binding parameters: question marks $id = 30; $q = $conn->prepare("SELECT * FROM pdo_db WHERE id > ?"); $q->execute(array($id)); // Here above ID will be passed named parameters $sth = $conn->prepare("SELECT `id`, `title` FROM `pdo_db` WHERE `id` > :id"); $sth->execute(array( ':id' => 30 )); Both are working fine and give accurate results but I am not able to get the exact differences between these two nor