pdo

Multiple Databases using PDO

孤者浪人 提交于 2019-12-25 04:46:08
问题 I'm pretty new to using PDO and I would like to set it up so I can have multiple databases as and when I need them. So I've created a function that allows you to pass a database name to be used as and when. It does work to a certain extent, as in it selects the database you pass in but even if the database is omitted or incorrect it still allows you to select tables and rows from a database which seems to be selected at random based on the MySQL user. This isn't a major issue I suppose but I

I get 2014 Cannot execute queries while other unbuffered queries are active when doing exec with PDO

梦想与她 提交于 2019-12-25 04:38:32
问题 I am doing a PDO::exec command on multiple updates: $MyPdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY,true); $MyPdo->exec("update t1 set f1=1;update t2 set f1=2"); I am doing it inside a transaction, and I keep getting the following error: SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by

How can PDO not return a row which pg_query() does?

允我心安 提交于 2019-12-25 04:27:24
问题 I had a table with a bigserial PK, one character varying FK and a bigint FK and a unique constraint on these FKs, a character varying NOT NULL and two nullable smallints. All of this was running in a VM with Ubuntu 14.04.2 LTS, PHP 5.5.9 and PostgreSQL 9.3 and all other packages from the distribution. I did $pdo->query("SELECT * FROM table")->fetchAll(PDO::FETCH_ASSOC) and $r = pg_query($db, "SELECT * FROM table"); pg_fetch_all($r) The latter returned all rows while the former returned all

PDO to retrieve and display images without creating files

。_饼干妹妹 提交于 2019-12-25 04:26:32
问题 Trying to loop through a test database with images (I know many say not to do this, but it simplifies so much in terms of backups, etc.). I can get the result I want by creating image files on the fly, but there must be a way to do this without creating files. Can someone suggest a syntax I can use without having to create these image files? Here is what I have working: <?php // configuration $dbhost = "localhost"; $dbname = "test"; $dbuser = "root"; $dbpass = ""; // database connection $conn

'Error!: could not find driver' after installing php_[pdo_]mssql.dll on WampServer

戏子无情 提交于 2019-12-25 04:24:13
问题 Similar questions seem to be all over the internet, but so far nothing has helped. I'm currently running WampServer with Apache 2.4.4 and PHP 5.4.12 on Windows Server 2008 R2. According to the PHP documentation the drivers necessary to connect to an MSSQL server ship with the distribution; they do not. Neither php_mssql.dll (which the documentation claims is no longer necessary for PHP5.4, but which is still referenced in php.ini . Who knows) nor php_pdo_mssql.dll are present in the

Can I mix MySQL APIs in PHP?

 ̄綄美尐妖づ 提交于 2019-12-25 04:21:55
问题 I have searched the net and so far what I have seen is that you can use mysql_ and mysqli_ together meaning: <?php $con=mysqli_connect("localhost", "root" ,"" ,"mysql"); if( mysqli_connect_errno( $con ) ) { echo "failed to connect"; }else{ echo "connected"; } mysql_close($con); echo "Done"; ?> or <?php $con=mysql_connect("localhost", "root" ,"" ,"mysql"); if( mysqli_connect_errno( $con ) ) { echo "failed to connect"; }else{ echo "connected"; } mysqli_close($con); echo "Done"; ?> Are valid but

How can I insert file from POST into longblob column using PHP 7 and MySQL?

蹲街弑〆低调 提交于 2019-12-25 04:16:07
问题 I'm using PHP 7 and MariaDB 5.5.47 (on CentOS 7) and the following code successfully executes, with no errors: $id = 3; $tmp_name = $_FILES['file']['tmp_name']; $fp = fopen($tmp_name, 'rb'); $statement = $db->prepare("INSERT INTO Foo (id, data) VALUES (?, ?)"); $statement->bindParam(1, $id); $statement->bindParam(2, $fp, PDO::PARAM_LOB); $statement->execute(); $statement->closeCursor(); close($fp); Using MySQL WorkBench it shows the "data" column is "BLOB" (as opposed to null, in the event I

Laravel 'could not find driver (SQL: insert into…'

只愿长相守 提交于 2019-12-25 04:14:17
问题 I'm trying to set up a development environment after not having done web dev in over a year. I've installed php 7.2.7 on my computer, then installed composer and WAMP. I'm using php artisan serve to set up a local server. I'm trying to create a new user in my database's 'users' table, using the following code in my web.php (routes) file. Route::get('/new', function(){ User::create([ 'password' => Hash::make('anything'), 'firstname' => 'Nick', 'lastname' => 'xyz', 'email' => 'xyz@ph.com',

PDO::FETCH_COLUMN fetches nothing

我们两清 提交于 2019-12-25 04:13:44
问题 The following code gives me an array $a containing description . $stmt = $dbh->prepare("SELECT description, id FROM money_items"); $stmt->execute(); $a = $stmt->fetchAll(PDO::FETCH_COLUMN, 0); $id = $stmt->fetchAll(PDO::FETCH_COLUMN, 1); But the $id array comes out blank. Array ( ) If I remove the $a = $stmt->fetchAll(PDO::FETCH_COLUMN, 0); line, the $id array comes out fine. Am I only allowed to fetch one column from the results? 回答1: what you are looking for is $results = $stmt->fetchAll

Why do I get 'Undefined offset: 0'?

这一生的挚爱 提交于 2019-12-25 04:05:26
问题 I'm develop a website and it looks fine. Then I turned on debugging to see if I had any errors, and I get this message: Notice: Undefined offset: 0 in I:\path\to\file\MyFile.class.php on line 105 On that line you will find the following code: $result = $stmt->fetchAll(PDO::FETCH_ASSOC); return $result[0]; // line 105 If I do a print_r(result) I get the following result: Array ( [0] => Array ( [id] => 3721 [parentID] => ) ) Array ( ) As you can see the result contains twoarrays. The first one