Search Results

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

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

  • Escapeing values in PDO statements

    - by Pardoner
    Doesn't prepare() escape any quotes(') in a PDO statement? For some reason when I do this: $sql = "INSERT INTO sessions (id, name) VALUES (1,'O'brian')"; $query = $this->connection->prepare($sql); $query->execute(); I get this error: Could not insert record SQLSTATE[42000]: [Microsoft][SQL Server Native Client 10.0][SQL Server]Incorrect syntax near 'brian'. How could this be if I'm using prepare()?

    Read the article

  • What's wrong with my using pdo this way?

    - by user198729
    $sql = "SELECT * FROM table ORDER BY :sort :dir LIMIT :start, :results"; $stmt = $dbh->prepare($sql); $stmt->execute(array( 'sort' => $_GET['sort'], 'dir' => $_GET['dir'], 'start' => $_GET['start'], 'results' => $_GET['results'], ) ); I tried to use prepare to do the job,but $stmt->fetchAll(PDO::FETCH_ASSOC); returns nothing.

    Read the article

  • How can I get a iterable resultset from the database using pdo, instead of a large array?

    - by Tchalvak
    I'm using PDO inside a database abstraction library function query. I'm using fetchAll(), which if you have a lot of results, can get memory intensive, so I want to provide an argument to toggle between a fetchAll associative array and a pdo result set that can be iterated over with foreach and requires less memory (somehow). I remember hearing about this, and I searched the PDO docs, but I couldn't find any useful way to do that. Does anyone know how to get an iterable resultset back from PDO instead of just a flat array? And am I right that using an iterable resultset will be easier on memory? I'm using Postgresql, if it matters in this case. . . . The current query function is as follows, just for clarity. /** * Running bound queries on the database. * * Use: query('select all from players limit :count', array('count'=>10)); * Or: query('select all from players limit :count', array('count'=>array(10, PDO::PARAM_INT))); **/ function query($sql_query, $bindings=array()){ DatabaseConnection::getInstance(); $statement = DatabaseConnection::$pdo->prepare($sql_query); foreach($bindings as $binding => $value){ if(is_array($value)){ $statement->bindParam($binding, $value[0], $value[1]); } else { $statement->bindValue($binding, $value); } } $statement->execute(); // TODO: Return an iterable resultset here, and allow switching between array and iterable resultset. return $statement->fetchAll(PDO::FETCH_ASSOC); }

    Read the article

  • PDO and SQL IN statements

    - by Sai
    Im using a sequel for search like this using PDOs $states = "'SC','SD'"; $sql = "select * from mytable where states in (:states)"; $params = array(':states'=>$states); and I use my function $result = $this->selectArrayAssoc($sql, $params); where my selectArrayAssoc function as following public function selectArrayAssoc($sql, $params = array()){ try{ $sth = $this->db->prepare($sql); $sth->execute($params); $result = $sth->setFetchMode(PDO::FETCH_ASSOC); return $sth->fetchAll(); }catch(PDOException $e){ print $e->getMessage(); //Log this to a file later when in production exit; } } it does not take the quoted variables, I think it is suppressing, in such cases how to deal with this.

    Read the article

  • PDO update with conditional?

    - by dmontain
    I have a PDO mysql that updates 3 fields. $update = $mypdo->prepare("UPDATE tablename SET field1=:field1, field2=:field2, field3=:field3 WHERE key=:key"); But I want field3 to be updated only when $update3 = true; Is this possible to accomplish with a single query? I could do it with 2 queries where I update field1 and field2 then check the boolean and update field3 if needed in a separate query. But hopefully there is a way to accomplish this in 1 query?

    Read the article

  • PDO update query with conditional?

    - by dmontain
    I have a PDO mysql that updates 3 fields. $update = $mypdo->prepare("UPDATE tablename SET field1=:field1, field2=:field2, field3=:field3 WHERE key=:key"); But I want field3 to be updated only when $update3 = true; (meaning that the update of field3 is controlled by a conditional statement) Is this possible to accomplish with a single query? I could do it with 2 queries where I update field1 and field2 then check the boolean and update field3 if needed in a separate query. //run this query to update only fields 1 and 2 $update_part1 = $mypdo->prepare("UPDATE tablename SET field1=:field1, field2=:field2 WHERE key=:key"); //if field3 should be update, run a separate query to update it separately if ($update3){ $update_part2 = $mypdo->prepare("UPDATE tablename SET field3=:field3 WHERE key=:key"); } But hopefully there is a way to accomplish this in 1 query?

    Read the article

  • Syntax for "RETURNING" clause in Mysql PDO

    - by dmontain
    I'm trying to add a record, and at the same time return the id of that record added. I read it's possible to do it with a RETURNING clause. $stmt->prepare("INSERT INTO tablename (field1, field2) VALUES (:value1, :value2) RETURNING id"); but the insertion fails when I add RETURNING. There is an auto-incremented field called id in the table being added to. Can someone see anything wrong with my syntax? or maybe PDO does not support RETURNING?

    Read the article

  • PHP PDO fetch null

    - by Jacob
    How do you check if a columns value is null? Example code: $db = DBCxn::getCxn(); $sql = "SELECT exercise_id, author_id, submission, result, submission_time, total_rating_votes, total_rating_values FROM submissions LEFT OUTER JOIN submission_ratings ON submissions.exercise_id=submission_ratings.exercise_id WHERE id=:id"; $st = $db->prepare($sql); $st->bindParam(":id", $this->id, PDO::PARAM_INT); $st->execute(); $row = $st->fetch(); if($this->total_rating_votes == null) // this doesn't seem to work even though there is no record in submission_ratings???? { ... }

    Read the article

  • PHP PDO Username Availability Checker

    - by John Bernal
    I'm building a registration page that uses JQuery's validator plugin to validate the form. For the username, i used the remote method. So here's my jquery+html code: fiddle And here's Available.php: <?php $usr = $_POST["username"]; $link = new PDO('mysql:***;dbname=***;charset=UTF-8','***','***'); $usr_check = $link->prepare("SELECT * FROM Conference WHERE Username = :usr"); $link->bindParam(':usr', $usr); $usr_check->execute(); if($usr_check->rowCount()>0) echo "false"; else echo "true"; ?> So I have a test account in my database with the username: user. When I tried to submit my form with the same username, it didn't display the error saying "username taken" which means the php isn't correct. Any ideas where I went wrong? Thanks

    Read the article

  • Cannot insert into SQLite database through php PDO

    - by user323941
    Pls help see what is wrong.... (I test the db connection is fine) <?php $user_name=$_POST['user_name']; $password=$_POST['password']; $dbh=new PDO('sqlite:./db/user.db') or die("fail to connect db"); try{ $stmt = $dbh->prepare("INSERT INTO user_info VALUES (?, ?)"); $stmt->bindParam(1, $a); $stmt->bindParam(2, $b); $a=$user_name; $b=$password; $stmt->execute(); } catch(PDOException $e) {echo $e->getMessage();} ?>

    Read the article

  • PDO - WHat is it? How do I enable it on shared hosting.

    - by Keith Groben
    I have a shared hosting account and PHP5 is installed and running. When I view phpinfo, I can see that mysql pdo is running. I think I need to "link" to it from the php.ini file. But I dont know for sure. I read that I needed to type "extension=pdo.so". I did that, and it did nothing. I contacted my hosting support, they said I need to rename php.ini to php5.ini. Did that and nothing. I am stuck and trying to install Kimai, but cannot without fixing this pdo problem. I have searched for a good hour and can find nothing to help me.

    Read the article

  • PDO lastInsertId issues, php

    - by Kyle Hudson
    Hi Guys, I have tried lots of ways to get the last inserted ID with the code below (snipplet from larger class) and now I have given up. Does anyone know howto get PDO lastInsertId to work? Thanks in advance. $sql = "INSERT INTO auth (surname, forename, email, mobile, mobilepin, actlink, regdate) VALUES (:surname, :forename, :email, :mobile, :mobpin, :actlink, NOW())"; $stmt = $this->dbh->prepare($sql); if(!$stmt) { return "st"; } $stmt->bindParam(':surname', $this->surname); $stmt->bindParam(':forename', $this->forename); $stmt->bindParam(':email', $this->email); $stmt->bindParam(':mobile', $this->mobile); $stmt->bindParam(':mobpin', $this->mobilePin); $stmt->bindParam(':actlink', $this->actlink); $result = $stmt->execute(); //return var_dump($result); $arr = array(); $arr = $stmt->errorInfo(); $_SESSION['record'] = 'OK' . $dbh->lastInsertId(); $arr .= $_SESSION['record']; return $arr;

    Read the article

  • PDO Database Connections Problem

    - by Metropolis
    Hey Everyone, Over a year ago I created my own database classes which use PDO, and handle all preparing, executing, and closing connections. These classes have been working great up until now. There are two different database severs I am grabbing from, MySQL, and MS SQL Express. I am retrieving an employee id from the MySQL server and using it to get that employees information from the MS SQL server. There are about 11k records coming from the MySQL server and my program is only making it through 1200 before crashing with an error like the following. Connection failed (odbc:Driver=FreeTDS;Servername=MSSQLExpress;Database=SMDINC) Class (PDOException) SQLSTATE[08001] SQLDriverConnect: 0 [unixODBC][FreeTDS][SQL Server]Unable to connect to data source It seems like the program is not able to connect to the data source, but it is running the exact same query about 30 times before this and having no problem. Also, I have thoroughly checked all of the data coming into the query and it all looks fine. I believe the issue may be that there are to many connections being created, but I have tried to close all connections in many different places, and nothing seems to be fixing the problem. Any debugging help, or suggestions would be appreciated! Craig Metrolis

    Read the article

  • PDO closeCursor Error

    - by Metropolis
    Hey Everyone, I currently have a database layer that I wrote myself and I have been using it now for over a year without any problems. The database class uses PDO, and there are two different databases that I regularly connect to (MySQL and MS SQL). The MS SQL database is used for Accpac accounting storage, and the MySQL database is used for everything else. In one of the MySQL databases I have all of the dsn's listed which I use to create the string I need to connect to the MS SQL databases. I have a new program I am trying to write which I am taking employee data from one of the MySQL databases, and using the employee ID to get the employee's information from the MS SQL database. For some reason, whenever I run the program it will get through about 1200 records (out of 11k) and then crash with an error like the following, Fatal error: Call to a member function closeCursor() on a non-object I have tried moving the loops around in many different ways, and I have tried manually closing the connections by setting the database handle to null. Nothing I do seems to work. Thanks for any help! Metropolis

    Read the article

  • Unable to retrieve data, mysql php pdo

    - by Kyle Hudson
    Hi, I have an issue, i cannot get any results from mysql on a production box but can on a development box, we use PHP 5.3 with MySQL (pdo). $sd = $this->dbh->quote($sd); $si_sql = "SELECT COUNT(*) FROM tbl_wl_data WHERE (site_domain = $sd OR siteDomainMasked = $sd);"; if($this->dbh->query($si_sql)->rowCount() > 0) { //gets to here, just doesnt get through the loop $sql = "SELECT pk_aid, site_name, site_css, site_img_sw, supportPhone FROM tbl_wl_data WHERE (site_domain = $sd OR siteDomainMasked = $sd);"; foreach($this->dbh->query($sql) as $wlsd) { //-- fails here if($wlsd['wl_status'] != '1') { require "_domainDisabled.php"; exit; } $this->pk_aid = $wlsd['pk_aid']; $this->siteTitle = $wlsd['site_name']; $this->siteCSS = $wlsd['site_css']; $this->siteImage = $wlsd['site_img_sw']; $this->siteSupportPhone = $wlsd['supportPhone']; } } else { throw new ERR_SITE_NOT_LINKED; } It just doesnt seem to get into the loopk, i ran the query in navicat and it returns the data. Really confused :S

    Read the article

  • Add to exisiting db values, rather than overwrite - PDO

    - by sam
    Im trying to add to existing decimal value in table, for which im using the sql below: UPDATE Funds SET Funds = Funds + :funds WHERE id = :id Im using a pdo class to handle my db calls, with the method below being used to update the db, but i couldnt figure out how to amend it to output the above query, any ideas ? public function add_to_values($table, $info, $where, $bind="") { $fields = $this->filter($table, $info); $fieldSize = sizeof($fields); $sql = "UPDATE " . $table . " SET "; for($f = 0; $f < $fieldSize; ++$f) { if($f > 0) $sql .= ", "; $sql .= $fields[$f] . " = :update_" . $fields[$f]; } $sql .= " WHERE " . $where . ";"; $bind = $this->cleanup($bind); foreach($fields as $field) $bind[":update_$field"] = $info[$field]; return $this->run($sql, $bind); }

    Read the article

  • Plans for our next milestone

    - by The Official Microsoft IIS Site
    We have seen some increase in activity with more people downloading our driver and either reporting their successes or reporting any issues they run into – for the native driver (sqlsrv_xxxx API) to the PDO driver (PDO API). We’d like to thank you all for your effort and hope that our responses were quick enough as well as accurate. To keep things simple, let us call the former the SQLSRV-PHP extension (php_sqlsrv.dll) whereas the latter will be the SQLSRV-PDO extension (php_pdo_sqlsrv...(read more)

    Read the article

  • Why is PHP5 SQLite PDO silently failing on DB connection?

    - by danieltalsky
    I have no idea why my code is failing silently. PDO and PDO SQLite are confirmed loaded. Errors are turned on and OTHER errors display. The SQLite file exists. Perms are set correctly. If I change the filename, PHP actually DOES create the file but still fails silently. No output or commands are excecuted after the "$dbh = new PDO($db_conn);" command. I'm not sure what else I can possibly do to troubleshoot. What else... this is on Modwest shared hosting. ABOUT TO RUN <?php // Destination $db_name = '/confirmed/valid/path/DBName.db3'; $db_conn = 'sqlite:' . $db_name; try { var_dump($db_conn); $dbh = new PDO($db_conn); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (Exception $e) { exit("Failed to open database: {$e->getMessage()} \n" ); } ?> THIS NEVER OUTPUTS! sdf

    Read the article

  • Why does PDO print my password when the connection fails?

    - by Joe Hopfgartner
    I have a simple website where I establish a connection to a Mysql server using PDO. $dbh = new PDO('mysql:host=localhost;dbname=DB;port=3306', 'USER', 'SECRET',array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")); I had some traffic on my site and the servers connection limit was reached, and the website throw this error, with my PLAIN password in it! Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[08004] [1040] Too many connections' in /home/premiumize-me/html/index.php:64 Stack trace: #0 /home/premiumize-me/html/index.php(64): PDO-__construct('mysql:host=loca...', 'USER', 'SECRET', Array) #1 {main} thrown in /home/premiumize-me/html/index.php on line 64 Ironically I switched to PDO for security reasons, this really shocked me. Because this exact error is something you can provoke very easily on most sites using simple http flooding. I now wrapped my conenction into a try/catch clause, but still. I think this is catastrophic! So I am new to PDO and my questino is: What do I have to consider to be safe! How to I establish a connection in a secure way? Are there other known security holes like this one that I have to be aware of?

    Read the article

  • What does Apache need to support both mysqli and PDO?

    - by Nathan Long
    I'm considering changing some PHP code to use PDO for database access instead of mysqli (because the PDO syntax makes more sense to me and is database-agnostic). To do that, I'd need both methods to work while I'm making the changeover. My problem is this: so far, either one or the other method will crash Apache. Right now I'm using XAMPP in Windows XP, and PHP Version 5.2.8. Mysqli works fine, and so does this: $dbc = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password); echo 'Connected to database'; $sql = "SELECT * FROM `employee`"; But this line makes Apache crash: $dbc->query($sql); I don't want to redo my entire Apache or XAMPP installation, but I'd like for PDO to work. So I tried updating libmysql.dll from here, as oddvibes recommended here. That made my simple PDO query work, but then mysqli queries crashed Apache. (I also tried the suggestion after that one, to update php_pdo_mysql.dll and php_pdo.dll, to no effect.) Test Case I created this test script to compare PDO vs mysqli. With the old copy of libmysql.dll, it crashes if $use_pdo is true and doesn't if it's false. With the new copy of libmysql.dll, it's the opposite. if ($use_pdo){ $dbc = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password); echo 'Connected to database<br />'; $sql = "SELECT * FROM `employee`"; $dbc->query($sql); foreach ($dbc->query($sql) as $row){ echo $row['firstname'] . ' ' . $row['lastname'] . "<br>\n"; } } else { $dbc = @mysqli_connect($hostname, $username, $password, $dbname) OR die('Could not connect to MySQL: ' . mysqli_connect_error()); $sql = "SELECT * FROM `employee`"; $result = @mysqli_query($dbc, $sql) or die(mysqli_error($dbc)); while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) { echo $row['firstname'] . ' ' . $row['lastname'] . "<br>\n"; } } What does Apache need in order to support both methods of database query?

    Read the article

  • PHP Multiple Calls to Server Share Objects?

    - by user1513171
    I’m wondering this about PHP on Apache. Do multiple calls to the server from different users—could be sitting next to each other, in different states, different countries, etc…—share memory? For example, if I create a static variable in a PHP script and set it to 1 by default, then user1 comes in and it changes to 2, and then almost at the exactly same time, user2 comes in, does he see that static variable with a value of 1 or 2? An even better example is this class I have in PHP: class ApplicationRegistry { private static $instance; private static $PDO; private function __construct() { self::$PDO = $db = new \PDO('mysql:unix_socket=/........'); self::$PDO->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); } static function instance() { if(!isset(self::$instance)) { self::$instance = new self(); } return self::$instance; } static function getDSN() { if(!isset(self::$PDO)) { self::instance(); return self::$PDO; } return self::$PDO; } } So this is a Singleton that has a static PDO instance. If user1 and user2 are hitting the server at the exact same time are they using different instances of PDO or are they using the same one? This is a confusing concept for me and I'm trying to think of how my application will scale.

    Read the article

  • PHP's PDO Prepare Method Fails While in a Loop

    - by Andrew G. Johnson
    Given the following code: // Connect to MySQL up here $example_query = $database->prepare('SELECT * FROM table2'); if ($example_query === false) die('prepare failed'); $query = $database->prepare('SELECT * FROM table1'); $query->execute(); while ($results = $query->fetch()) { $example_query = $database->prepare('SELECT * FROM table2'); if ($example_query === false) die('prepare failed'); //it will die here } I obviously attempt to prepare statements to SELET everything from table2 twice. The second one (the one in the WHILE loop) always fails and causes an error. This is only on my production server, developing locally I have no issues so it must be some kind of setting somewhere. My immediate thought is that MySQL has some kind of max_connections setting that is set to 1 and a connection is kept open until the WHILE loop is completed so when I try to prepare a new query it says "nope too many connected already" and shits out. Any ideas? EDIT: Yes I know there's no need to do it twice, in my actual code it only gets prepared in the WHILE loop, but like I said that fails on my production server so after some testing I discovered that a simple SELECT * query fails in the WHILE loop but not out of it. The example code I gave is obviously very watered down to just illustrate the issue.

    Read the article

  • PDO prepared statement not working for login system

    - by Cortopasta
    Anybody no what I'm doing wrong here? I have a username and password hashed in my database, but i can't seem to get it to match the one I submit through the script. $res = $dbcon->prepare('SELECT id FROM users WHERE name = :name AND password = MD5(:password)'); $res->bindParam(':name', $user); $res->bindParam(':password', $password); $res->execute(); $row = $res->fetch(); for ($i=0; $i<7; $i++) { $row[$i]; }

    Read the article

  • WHERE clause confusion with PDO

    - by Greg
    I'm having some trouble understanding how to use prepared statements, when you need to match one value against several columns at once. In other words what instead of doing this: $stmt = $dbh-prepare("SELECT * FROM REGISTRY where name = ?"); $stmt-bindParam(':name', $name); I wanted to do this: $stmt = $dbh-prepare("SELECT * FROM REGISTRY where firstname = ? or lastname = ?"); with both '?' representing the same string.

    Read the article

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