Search Results

Search found 344 results on 14 pages for 'pdo'.

Page 2/14 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • PHP PDO Related: Update SQL Statement not Updating the content of Database

    - by Rachel
    I am trying to implement update statement using prepared statement in php script but it appears that it is not update record in the database and am not sure why and so would appreciate if you can share some insights. Code $query = "UPDATE DatTable SET DF_PARTY_ID = :party_id, DF_PARTY_CODE = :party_code, DF_CONNECTION_ID = :connection_id WHERE DF_PARTY_ID = ':party_id'"; $stmt = $this->connection->prepare($query); $stmt->bindValue(':party_id', $data[0], PDO::PARAM_INT); $stmt->bindValue(':party_code', $data[1], PDO::PARAM_INT); $stmt->bindValue(':connection_id', $data[2], PDO::PARAM_INT); $stmt->execute(); Inspiring Solution leading to this approach. Any Suggestions ?

    Read the article

  • PHP PDO - bindValue PARAM_BOOL as string

    - by PHP_guy
    I'm freaking out here and can't figure out what's wrong. I'm pretty new to PDO, but everything works in my code except for booleans which are sent as strings. My code (simplified): $sql = 'SELECT * FROM pages WHERE clean_url_slo = :clean_url_slo AND published = :published LIMIT 1'; $clean_url_slo = 'home'; $published = true; Then I prepare stuff and execute it like this (simplified): $stmt = $db->prepare($sql); $stmt->bindValue(':clean_url_slo',$clean_url_slo,PDO::PARAM_STR); $stmt->bindValue(':published',$published,PDO::PARAM_BOOL); $stmt->execute(); And then here is what comes to mysql (from the mysql log - the query mysql received): 91 Query SELECT * FROM pages WHERE 1=1 AND clean_url_slo='domov' AND published='1' ORDER BY id desc LIMIT 1 As you can see, published is an integer - so always true, which is not OK. Why is that if I'm declaring it as a boolean? using: WAMP SERVER PHP version: 5.3.9 Mysql: 5.5.20 Many thanks for your help..

    Read the article

  • Why won't the following PDO transaction won't work in PHP?

    - by jfizz
    I am using PHP version 5.4.4, and a MySQL database using InnoDB. I had been using PDO for awhile without utilizing transactions, and everything was working flawlessly. Then, I decided to try to implement transactions, and I keep getting Internal Server Error 500. The following code worked for me (doesn't contain transactions). try { $DB = new PDO('mysql:host=localhost;dbname=database', 'root', 'root'); $DB->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $dbh = $DB->prepare("SELECT * FROM user WHERE username = :test"); $dbh->bindValue(':test', $test, PDO::PARAM_STR); $dbh->execute(); } catch(Exception $e){ $dbh->rollback(); echo "an error has occured"; } Then I attempted to utilize transactions with the following code (which doesn't work). try { $DB = new PDO('mysql:host=localhost;dbname=database', 'root', 'root'); $DB->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $dbh = $DB->beginTransaction(); $dbh->prepare("SELECT * FROM user WHERE username = :test"); $dbh->bindValue(':test', $test, PDO::PARAM_STR); $dbh->execute(); $dbh->commit(); } catch(Exception $e){ $dbh->rollback(); echo "an error has occured"; } When I run the previous code, I get an Internal Server Error 500. Any help would be greatly appreciated! Thanks!

    Read the article

  • PDO fails to prepare a statement with over 13 placeholders

    - by Javier Parra
    Hello, this is the code I'm using: self::$DB->prepare($query, $types); when the $query and types are: //$query UPDATE Permisos SET empleado_id = ?, agregar_mensaje = ?, borrar_mensaje = ?, agregar_noticia = ?, borrar_noticia = ?, agregar_documento = ?, borrar_documento = ?, agregar_usuario = ?, borrar_usuario = ?, agregar_empresa = ?, borrar_empresa = ?, agregar_tarea = ? WHERE id = ? //$types Array( [0] => integer [1] => boolean [2] => boolean [3] => boolean [4] => boolean [5] => boolean [6] => boolean [7] => boolean [8] => boolean [9] => boolean [10] => boolean [11] => boolean [12] => integer ) Everything works great, but when they are: //$query UPDATE Permisos SET empleado_id = ?, agregar_mensaje = ?, borrar_mensaje = ?, agregar_noticia = ?, borrar_noticia = ?, agregar_documento = ?, borrar_documento = ?, agregar_usuario = ?, borrar_usuario = ?, agregar_empresa = ?, borrar_empresa = ?, agregar_tarea = ?, borrar_tarea = ? WHERE id = ? //$types Array( [0] => integer [1] => boolean [2] => boolean [3] => boolean [4] => boolean [5] => boolean [6] => boolean [7] => boolean [8] => boolean [9] => boolean [10] => boolean [11] => boolean [12] => boolean [13] => integer ) It fails with the following message: <b>Warning</b>: PDO::prepare() [<a href='pdo.prepare'>pdo.prepare</a>]: SQLSTATE[HY000]: General error: PDO::ATTR_STATEMENT_CLASS requires format array(classname, array(ctor_args)); the classname must be a string specifying an existing class in <b>C:\wamp\www\intratin\JP\includes\empleado\mapper\Permiso.php</b> on line <b>137</b><br /> Doesn't matter which field I add or remove, it fails every time with more than 13 placeholders.

    Read the article

  • Sqlite3 and PDO problem with ORDER BY

    - by Maenny
    Hi, I try to use the SQL statement SELECT * FROM table ORDER BY column via an PDO-Object in PHP. Problem is, that I always get an error (Call to a member function fetchall() on a non-object - that means, the query did not return a PDO-object) when using the names of all columnname EXCEPT for ID. When I query SELECT * FROM table ORDER BY ID it works. ID is the PRIMARY INTEGER KEY, all other columns are TEXT or NUMERIC, neither of them would works with the ORDER BY clause. Any ideas?

    Read the article

  • How does PHP PDO work internally ?

    - by Rachel
    I want to use pdo in my application, but before that I want to understand how internally PDOStatement->fetch and PDOStatement->fetchAll. For my application, I want to do something like "SELECT * FROM myTable" and insert into csv file and it has around 90000 rows of data. My question is, if I use PDOStatement->fetch as I am using it here: // First, prepare the statement, using placeholders $query = "SELECT * FROM tableName"; $stmt = $this->connection->prepare($query); // Execute the statement $stmt->execute(); var_dump($stmt->fetch(PDO::FETCH_ASSOC)); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo "Hi"; // Export every row to a file fputcsv($data, $row); } Will after every fetch from database, result for that fetch would be store in memory ? Meaning when I do second fetch, memory would have data of first fetch as well as data for second fetch. And so if I have 90000 rows of data and if am doing fetch every time than memory is being updated to take new fetch result without removing results from previous fetch and so for the last fetch memory would already have 89999 rows of data. Is this how PDOStatement::fetch works ? Performance wise how does this stack up against PDOStatement::fetchAll ?

    Read the article

  • singleton factory connection pdo

    - by Scarface
    Hey guys I am having a lot of trouble trying to understand this and I was just wondering if someone could help me with some questions. I found some code that is supposed to create a connection with pdo. The problem I was having was having my connection defined within functions. Someone suggested globals but then pointed to a 'better' solution http://stackoverflow.com/questions/130878/global-or-singleton-for-database-connection. My questions with this code are. PS I cannot format this code on this page so see the link if you cannot read What is the point of the connection factory? What goes inside new ConnectionFactory(...) When the connection is defined $db = new PDO(...); why is there no try or catch (I use those for error handling)? Does this then mean I have to use try and catch for every subsequent query? class ConnectionFactory { private static $factory; public static function getFactory() { if (!self::$factory) self::$factory = new ConnectionFactory(...); return self::$factory; } private $db; public function getConnection() { if (!$db) $db = new PDO(...); return $db; } } function getSomething() { $conn = ConnectionFactory::getFactory()-getConnection(); . . . }

    Read the article

  • Any suggestions to improve my PDO connection class?

    - by Scarface
    Hey guys I am pretty new to pdo so I basically just put together a simple connection class using information out of the introductory book I was reading but is this connection efficient? If anyone has any informative suggestions, I would really appreciate it. class PDOConnectionFactory{ public $con = null; // swich database? public $dbType = "mysql"; // connection parameters public $host = "localhost"; public $user = "user"; public $senha = "password"; public $db = "database"; public $persistent = false; // new PDOConnectionFactory( true ) <--- persistent connection // new PDOConnectionFactory() <--- no persistent connection public function PDOConnectionFactory( $persistent=false ){ // it verifies the persistence of the connection if( $persistent != false){ $this->persistent = true; } } public function getConnection(){ try{ $this->con = new PDO($this->dbType.":host=".$this->host.";dbname=".$this->db, $this->user, $this->senha, array( PDO::ATTR_PERSISTENT => $this->persistent ) ); // carried through successfully, it returns connected return $this->con; // in case that an error occurs, it returns the error; }catch ( PDOException $ex ){ echo "We are currently experiencing technical difficulties. We have a bunch of monkies working really hard to fix the problem. Check back soon: ".$ex->getMessage(); } } // close connection public function Close(){ if( $this->con != null ) $this->con = null; } }

    Read the article

  • PHP PDO MySQL IN (?,?,?...

    - by nute
    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(':idList', implode(',', $idArray)); Is that possible?

    Read the article

  • Work-around for PHP5's PDO rowCount MySQL issue

    - by Steven Surowiec
    I've recently started work on a new project using PHP5 and want to use their PDO classes for it. The problem is that the MySQL PDO Driver doesn't support rowCount() so there's no way to run a query and then get the number of affected rows, or rows returned, which is a pretty big issue as far as I'm concerned. I was wondering if anyone else has dealt with this before and what you've done to work around it. Having to do a fetch() or fetchAll() to check if any rows were affected or returned seems like a hack to me, I'd rather just do $stmt-numRows() or something similar.

    Read the article

  • php pdo connection scope

    - by Scarface
    Hey guys I have a connection class I found for pdo. I am calling the connection method on the page that the file is included on. The problem is that within functions the $conn variable is not defined even though I stated the method was public (bare with me I am very new to OOP), and I was wondering if anyone had an elegant solution other then using global in every function. Any suggestions are greatly appreciated. CONNECTION class PDOConnectionFactory{ // receives the connection public $con = null; // swich database? public $dbType = "mysql"; // connection parameters // when it will not be necessary leaves blank only with the double quotations marks "" public $host = "localhost"; public $user = "user"; public $senha = "password"; public $db = "database"; // arrow the persistence of the connection public $persistent = false; // new PDOConnectionFactory( true ) <--- persistent connection // new PDOConnectionFactory() <--- no persistent connection public function PDOConnectionFactory( $persistent=false ){ // it verifies the persistence of the connection if( $persistent != false){ $this->persistent = true; } } public function getConnection(){ try{ // it carries through the connection $this->con = new PDO($this->dbType.":host=".$this->host.";dbname=".$this->db, $this->user, $this->senha, array( PDO::ATTR_PERSISTENT => $this->persistent ) ); // carried through successfully, it returns connected return $this->con; // in case that an error occurs, it returns the error; }catch ( PDOException $ex ){ echo "We are currently experiencing technical difficulties. We have a bunch of monkies working really hard to fix the problem. Check back soon: ".$ex->getMessage(); } } // close connection public function Close(){ if( $this->con != null ) $this->con = null; } } PAGE USED ON include("includes/connection.php"); $db = new PDOConnectionFactory(); $conn = $db->getConnection(); function test(){ try{ $sql = 'SELECT * FROM topic'; $stmt = $conn->prepare($sql); $result=$stmt->execute(); } catch(PDOException $e){ echo $e->getMessage(); } } test();

    Read the article

  • PDO Prepare statement not processing parameters

    - by Danten
    I've exhausted all efforts at what appears to be a trivial problem, but gotten nowhere. There is a simple Prepare statement: $qry = $core->db->prepare("SELECT * FROM users WHERE email = '?'"); $qry->execute(array('[email protected]')); However, no rows are returned. Running the query with the parameters hardcoded into the query results in a successful selection of one row. I've tryed many different methods of doing the prepare, but even it this most simple form it isn't working. The PDO object is stored in a singleton called Core. PDO is using the mysql driver.

    Read the article

  • pdo connection scope

    - by Scarface
    Hey guys I have a connection class I found for pdo. I am calling the connection method on the page that the file is included on. The problem is that within functions the $conn variable is not defined even though I stated the method was public (bare with me I am very new to OOP), and I was wondering if anyone had an elegant solution other then using global in every function. Any suggestions are greatly appreciated. CONNECTION class PDOConnectionFactory{ // receives the connection public $con = null; // swich database? public $dbType = "mysql"; // connection parameters // when it will not be necessary leaves blank only with the double quotations marks "" public $host = "localhost"; public $user = "user"; public $senha = "password"; public $db = "database"; // arrow the persistence of the connection public $persistent = false; // new PDOConnectionFactory( true ) <--- persistent connection // new PDOConnectionFactory() <--- no persistent connection public function PDOConnectionFactory( $persistent=false ){ // it verifies the persistence of the connection if( $persistent != false){ $this->persistent = true; } } public function getConnection(){ try{ // it carries through the connection $this->con = new PDO($this->dbType.":host=".$this->host.";dbname=".$this->db, $this->user, $this->senha, array( PDO::ATTR_PERSISTENT => $this->persistent ) ); // carried through successfully, it returns connected return $this->con; // in case that an error occurs, it returns the error; }catch ( PDOException $ex ){ echo "We are currently experiencing technical difficulties. We have a bunch of monkies working really hard to fix the problem. Check back soon: ".$ex->getMessage(); } } // close connection public function Close(){ if( $this->con != null ) $this->con = null; } } PAGE USED ON include("includes/connection.php"); $db = new PDOConnectionFactory(); $conn = $db->getConnection(); function test(){ try{ $sql = 'SELECT * FROM topic'; $stmt = $conn->prepare($sql); $result=$stmt->execute(); } catch(PDOException $e){ echo $e->getMessage(); } } test();

    Read the article

  • PHP PDO SQL Server Select statement not replacing question marks

    - by Metropolis
    Awhile ago I wrote a database class which uses PDO in order to connect to SQL Server databases and also to MySQL databases. It has always replaced the question marks fine when using it on the MySQL databases, but for the SQL Server database I had to create a work around which basically replaces the question marks manually. Here is the code for that. if($this->getPDODriver() == 'odbc' && !empty($values_a) && substr_count($query_s, "?") > 0) { $query_s = preg_replace(array_fill(0, substr_count($query_s, "?"), '/\?/'), $values_a, $query_s, 1); $values_a = NULL; } Now, I understand that this completely defeats the purpose of the question marks and PDO, but it has been working fine for me. What I would like to do now though, is find out why the question marks are not getting replaced in the first place, and remove this workaround. If I have a select statement like the following SELECT * FROM database WHERE value = ? That is what the query looks like when I go to prepare it, but when I display the query results, it is a blank array. Just remember, this class is working fine with MySQL, and it is working fine with the work around above. So I know it has something to do with the question marks.

    Read the article

  • PDO using singleton stored as class properity

    - by Misiur
    Hi again. OOP drives me crazy. I can't move PDO to work. Here's my DB class: class DB extends PDO { public function &instance($dsn, $username = null, $password = null, $driver_options = array()) { static $instance = null; if($instance === null) { try { $instance = new self($dsn, $username, $password, $driver_options); } catch(PDOException $e) { throw new DBException($e->getMessage()); } } return $instance; } } It's okay when i do something like this: try { $db = new DB(DB_TYPE.':host='.DB_HOST.';dbname='.DB_NAME, DB_USER, DB_PASS); } catch(DBException $e) { echo $e->getMessage(); } But this: try { $db = DB::instance(DB_TYPE.':host='.DB_HOST.';dbname='.DB_NAME, DB_USER, DB_PASS); } catch(DBException $e) { echo $e->getMessage(); } Does nothing. I mean, even when I use wrong password/username, I don't get any exception. Second thing - I have class which is "heart" of my site: class Core { static private $instance; public $db; public function __construct() { if(!self::$instance) { $this->db = DB::instance(DB_TYPE.':hpost='.DB_HOST.';dbname='.DB_NAME, DB_USER, DB_PASS); } return self::$instance; } private function __clone() { } } I've tried to use "new DB" inside class, but this: $r = $core->db->query("SELECT * FROM me_config"); print_r($r->fetch()); Return nothing. $sql = "SELECT * FROM me_config"; print_r($core->db->query($sql)); I get: PDOStatement Object ( [queryString] => SELECT * FROM me_config ) I'm really confused, what am I doing wrong?

    Read the article

  • XAMPP, MAMP, MySQL, PDO - A deadly combination?

    - by Rich
    Hey folks, Previously I've worked on a Symfony project (MySQL PDO based) with XAMPP, with no problems. Since then, I've moved to MAMP - I prefer this - but have hit a snag with my database connection. I've created a test.php like this: <?php try { $dbh = new PDO('mysql:host=localhost;dbname=xxx;port=8889', 'xxx', 'xxx'); foreach($dbh->query('SELECT * from FOO') as $row) { print_r($row); } $dbh = null; } catch (PDOException $e) { print "Error!: " . $e->getMessage() . "<br/>"; die(); } ?> Obviously the *xxx*s are real db connection details. Which when served by MAMP seems to work fine. From terminal however I keep getting the following error when running the file: Error!: SQLSTATE[28000] [1045] Access denied for user 'xxx'@'localhost' (using password: YES) Not sure if the terminal is aiming at a different MySQL socket or something along those lines; but I've tried pointing it to the MAMP socket with a local php.ini file. Any help would be greatly appreciated.

    Read the article

  • PHP PDO Parameters from a function returned array

    - by noko
    I've got a function written that runs a query based on parameters passed to the function. I can't seem to figure out why doing the following returns a result: function test($function_returned_array) { $variable = 'Hello World'; $sql = 'SELECT `name`, `pid` FROM `products` WHERE `name` IN (?)'; $found = $this->db->get_array($sql, $variable); } While this doesn't return any results: function test2($function_returned_array) { $sql = 'SELECT `name`, `pid` FROM `products` WHERE `name` IN (?)'; $found = $this->db->get_array($sql, $function_returned_array[0]); } $function_returned_array[0] is also equal to 'Hello World'. Shouldn't they both return the same results? When I echo the values of $variable and $function_returned_array[0], they are both 'Hello World' Here's the relevant parts of my PDO wrapper: public function query(&$query, $params) { $sth = $this->_db->prepare($query); if(is_null($params)) { $sth->execute(); } else if(is_array($params)) { $sth->execute($params); } else { $sth->execute(array($params)); } $this->_rows = $sth->rowCount(); $this->_counter++; return $sth; } public function get_array(&$query, $params, $style = PDO::FETCH_ASSOC) { $q = $this->query($query, $params); return $q->fetchAll($style); } I'm using PHP 5.3.5. Any help would be appreciated.

    Read the article

  • Questions about shifting from mysql to PDO

    - by Scarface
    Hey guys I have recently decided to switch all my current plain mysql queries performed with php mysql_query to PDO style queries to improve performance, portability and security. I just have some quick questions for any experts in this database interaction tool Will it prevent injection if all statements are prepared? (I noticed on php.net it wrote 'however, if other portions of the query are being built up with unescaped input, SQL injection is still possible' I was not exactly sure what this meant). Does this just mean that if all variables are run through a prepare function it is safe, and if some are directly inserted then it is not? Currently I have a connection at the top of my page and queries performed during the rest of the page. I took a look at PDO in more detail and noticed that there is a try and catch procedure for every query involving a connection and the closing of that connection. Is there a straightforward way to connecting and then reusing that connection without having to put everything in a try or constantly repeat the procedure by connecting, querying and closing? Can anyone briefly explain in layman's terms what purpose a set_exception_handler serves? I appreciate any advice from any more experienced individuals.

    Read the article

  • PHP PDO changes remote host to local hostname

    - by Wade Urry
    I'm trying to connect to a remote mysql server using PDO. However, regardless of the hostname or ip address i supply in the dsn, when the script is run it always reverts the address to the hostname of the local server where the webserver is running. Google suggests this could be something to do with SELinux and apaches ability to connect to remote databases, however i have SELinux disabled. Distro: Ubuntu 11.04 x64 Apache version: 2.2.17 PHP Version: PHP 5.3.5-1ubuntu7.11 with Suhosin-Patch (cli) Edit: Added code as requested. Though i dont believe this is an issue with my coding as it works fine on the local server, but doesnt allow remote connection. public function db_connect($driver, $dbhost, $dbname, $user, $pass) { $dsn = $driver . ':host=' . $dbhost . ';dbname=' . $dbname; try { $this->DB = new PDO($dsn, $user, $pass); } catch (PDOException $err) { print 'Database Connection Failed: ' . $err->getMessage(); die(); } } $remote_db = new DB('mysql', 'remote_server.domain.tld', 'database_name', 'user_name', 'password'); This is the error message i am receiving. Database Connection Failed: SQLSTATE[28000] [1045] Access denied for user 'user_name'@'local_server.domain.tld' (using password: YES)

    Read the article

  • mysql PDO how to bind LIKE

    - by dmontain
    In this query select wrd from tablename WHERE wrd LIKE '$partial%' I'm trying to bind the variable '$partial%' with PDO. Not sure how this works with the % at the end. Would it be select wrd from tablename WHERE wrd LIKE ':partial%' where :partial is bound to $partial="somet" or would it be select wrd from tablename WHERE wrd LIKE ':partial' where :partial is bound to $partial="somet%" or would it be something entirely different?

    Read the article

  • PHP PDO - Num Rows

    - by Ian
    PDO apparently has no means to count the number of rows returned from a select query (mysqli has the num_rows variable). Is there a way to do this, short of using count($results->fetchAll()) ?

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >