Search Results

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

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

  • Problem creating a database with PHP PDO

    - by Leandro Alonso
    Hello guys, I'm having a problem with a SQL query in my PHP Application. When the user access it for the first time, the app executes this query to create all the database: CREATE TABLE `databases` ( `id` bigint(20) NOT NULL auto_increment, `driver` varchar(45) NOT NULL, `server` text NOT NULL, `user` text NOT NULL, `password` text NOT NULL, `database` varchar(200) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; -- -------------------------------------------------------- -- -- Table structure for table `modules` -- CREATE TABLE `modules` ( `id` bigint(20) unsigned NOT NULL auto_increment, `title` varchar(100) NOT NULL, `type` varchar(150) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=29 ; -- -------------------------------------------------------- -- -- Table structure for table `modules_data` -- CREATE TABLE `modules_data` ( `id` bigint(20) NOT NULL auto_increment, `module_id` bigint(20) unsigned NOT NULL, `key` varchar(150) NOT NULL, `value` tinytext, PRIMARY KEY (`id`), KEY `fk_modules_data_modules` (`module_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=184 ; -- -------------------------------------------------------- -- -- Table structure for table `modules_position` -- CREATE TABLE `modules_position` ( `user_id` bigint(20) unsigned NOT NULL, `tab_id` bigint(20) unsigned NOT NULL, `module_id` bigint(20) unsigned NOT NULL, `column` smallint(1) default NULL, `line` smallint(1) default NULL, PRIMARY KEY (`user_id`,`tab_id`,`module_id`), KEY `fk_modules_order_users` (`user_id`), KEY `fk_modules_order_tabs` (`tab_id`), KEY `fk_modules_order_modules` (`module_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -------------------------------------------------------- -- -- Table structure for table `tabs` -- CREATE TABLE `tabs` ( `id` bigint(20) unsigned NOT NULL auto_increment, `title` varchar(60) NOT NULL, `columns` smallint(1) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=12 ; -- -------------------------------------------------------- -- -- Table structure for table `tabs_has_modules` -- CREATE TABLE `tabs_has_modules` ( `tab_id` bigint(20) unsigned NOT NULL, `module_id` bigint(20) unsigned NOT NULL, PRIMARY KEY (`tab_id`,`module_id`), KEY `fk_tabs_has_modules_tabs` (`tab_id`), KEY `fk_tabs_has_modules_modules` (`module_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -------------------------------------------------------- -- -- Table structure for table `users` -- CREATE TABLE `users` ( `id` bigint(20) unsigned NOT NULL auto_increment, `login` varchar(60) NOT NULL, `password` varchar(64) NOT NULL, `email` varchar(100) NOT NULL, `name` varchar(250) default NULL, `user_level` bigint(20) unsigned NOT NULL, PRIMARY KEY (`id`), KEY `fk_users_user_levels` (`user_level`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ; -- -------------------------------------------------------- -- -- Table structure for table `users_has_tabs` -- CREATE TABLE `users_has_tabs` ( `user_id` bigint(20) unsigned NOT NULL, `tab_id` bigint(20) unsigned NOT NULL, `order` smallint(2) NOT NULL, `columns_width` varchar(255) default NULL, PRIMARY KEY (`user_id`,`tab_id`), KEY `fk_users_has_tabs_users` (`user_id`), KEY `fk_users_has_tabs_tabs` (`tab_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -------------------------------------------------------- -- -- Table structure for table `user_levels` -- CREATE TABLE `user_levels` ( `id` bigint(20) unsigned NOT NULL auto_increment, `level` smallint(2) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ; -- -------------------------------------------------------- -- -- Table structure for table `user_meta` -- CREATE TABLE `user_meta` ( `id` bigint(20) unsigned NOT NULL auto_increment, `user_id` bigint(20) unsigned default NULL, `key` varchar(150) NOT NULL, `value` longtext NOT NULL, PRIMARY KEY (`id`), KEY `fk_user_meta_users` (`user_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ; -- -- Constraints for dumped tables -- -- -- Constraints for table `modules_data` -- ALTER TABLE `modules_data` ADD CONSTRAINT `fk_modules_data_modules` FOREIGN KEY (`module_id`) REFERENCES `modules` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION; -- -- Constraints for table `modules_position` -- ALTER TABLE `modules_position` ADD CONSTRAINT `fk_modules_order_modules` FOREIGN KEY (`module_id`) REFERENCES `modules` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION, ADD CONSTRAINT `fk_modules_order_tabs` FOREIGN KEY (`tab_id`) REFERENCES `tabs` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION, ADD CONSTRAINT `fk_modules_order_users` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION; -- -- Constraints for table `users` -- ALTER TABLE `users` ADD CONSTRAINT `fk_users_user_levels` FOREIGN KEY (`user_level`) REFERENCES `user_levels` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION; -- -- Constraints for table `user_meta` -- ALTER TABLE `user_meta` ADD CONSTRAINT `fk_user_meta_users` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION; INSERT INTO `user_levels` VALUES(1, 10); INSERT INTO `user_levels` VALUES(2, 1); INSERT INTO `users` VALUES(1, 'admin', 'password', '[email protected]', NULL, 1); INSERT INTO `user_meta` VALUES (NULL, 1, 'last_tab', 1); In some environments i get this error: SQLSTATE[HY000]: General error: 1005 Can't create table 'dms.databases' (errno: 150) I tried everything that I could find on Google but nothing works. The strange part is that if I run this query in PhpMyAdmin he creates my database, without any error.

    Read the article

  • PHP PDO close()?

    - by PHPLOVER
    Can someone tell me, when you for example update, insert, delete.. should you then close it like $stmt->close(); ? i checked php manual and don't understand what close() actually does. EXAMPLE: $stmt = $dbh->prepare("SELECT `user_email` FROM `users` WHERE `user_email` = ? LIMIT 1"); $stmt->execute(array($email)); $stmt->close(); Next part of my question is, if as an example i had multiple update queries in a transaction after every execute() for each query i am executing should i close them individually ? ... because it's a transaction not sure i need to use $stmt->close(); after each execute(); or just use one $stmt->close(); after all of them ? Thanks once again, phplover

    Read the article

  • Is this pdo bug fixed now?

    - by user198729
    Note that you can specify a port number with "port=####", but this port number will be ignored if the host is localhost. If you want to connect to a local port other than the default, use host=127.0.0.1 instead of localhost. Quoted from this page,has anyone verified if it has been fixed?

    Read the article

  • problems, custum wrap (class) around PDO, doesn't work

    - by Knarf
    DB::construct(); $STH = DB::prepare('INSERT INTO users (username, password, email, activationkey) VALUES (?, UNHEX(?), ?, ?)'); var_dump($STH); $result = $STH->execute(array('test', 'nils', '[email protected]', '227a038fe9c81515b514cb152188e95c')); echo "working? <br />"; if($result == false) echo 'noooo...'; It outputs and doesn't put anything in the database. Works with a similare code with DPO just without my DB class. But I doesn't get any errors. Anyone have an idea what the problem could be? object(PDOStatement)#2 (1) { ["queryString"]=> string(87) "INSERT INTO users (username, password, email, activationkey) VALUES (?, UNHEX(?), ?, ?)" } working? <br /> noooo...

    Read the article

  • PDO:sqlite doesnt INSERT data, yet no error

    - by Phonethics
    try { $res = $db-exec($sql); if ($res === FALSE) { print_r($db-errorInfo()); die(); } } catch(PDOException $e) { die($e-getCode().':'.$e-getMessage()); } catch(Exception $e) { die($e-getCode().':'.$e-getMessage()); } No error info, and neither does it get caught as an exception. Yet $res is FALSE and no data gets inserted. Array ( [0] => ) But when I echo $sql and enter that query in SQLiteManager, it works inserting the data.

    Read the article

  • update entire table with pdo

    - by MephDaddy
    I am working on a simple gaming ladder script. I am having little to no luck trying to find an effective way to reset my ladder information while leaving my table id and name fields intact. I am trying to get create a loop to update my entire table, similar to the way I draw my table. Shown below. ...... //Start displaying ladder with with team with most wins at the top echo "<TABLE border=1 width=500 align=center><TR>"; foreach($db->query('SELECT * FROM test ORDER BY win DESC , name ASC') as $row) { echo "<TR><TD>" . $row['name'] . "</TD><TD>" . $row['win'] . "</TD><TD>"; echo $row['loss'] . "</TD><TD>" . $row['battles'] . "</TD><TD>"; echo $row['score'] . "</TD></TR>"; } ...... I currently have a table with 6 fields(id,name,win,loss,battles,score). I want to reset the values of win,loss,battles, and score back to 0. While leaving id and name alone. Effective reseting my ladder for a new season to begin. The only way I have been able to complete this is to find out how many rows there are and run a for loop. It seems vary inefficient. Was hoping I could get some better insight as to how to go about this.

    Read the article

  • How do I set ORDER BY params using prepated PDO statement?

    - by Marlorn
    I'm having problems using params in the ORDER BY section of my SQL. It doesn't issue any warnings, but prints out nothing. $order = 'columnName'; $direction = 'ASC'; $stmt = $db->prepare("SELECT field from table WHERE column = :my_param ORDER BY :order :direction"); $stmt->bindParam(':my_param', $is_live, PDO::PARAM_STR); $stmt->bindParam(':order', $order, PDO::PARAM_STR); $stmt->bindParam(':direction', $direction, PDO::PARAM_STR); $stmt->execute(); The :my_param works, but not :order or :direction. Is it not being internally escaped correctly? Am I stuck inserting it directly in the SQL? Like so: $order = 'columnName'; $direction = 'ASC'; $stmt = $db->prepare("SELECT * from table WHERE is_live = :is_live ORDER BY $order $direction"); Is there a PDO::PARAM_COLUMN_NAME constant or some equivalent? Thanks!

    Read the article

  • Where can I find an introduction to using PDO?

    - by aslum
    I know my SQL safety isn't up to par. I've read on this site that PHP PDO would be a good first step, and while I did take a look at the PDO Manual it's a bit daunting. Is there somewhere I can find a tutorial on the basics of using PDO rather then straight MySQL calls?

    Read the article

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

    - by Itay Moav
    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: 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 setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute. those are the only query/ies

    Read the article

  • How do I set ORDER BY params using prepared PDO statement?

    - by Marlorn
    I'm having problems using params in the ORDER BY section of my SQL. It doesn't issue any warnings, but prints out nothing. $order = 'columnName'; $direction = 'ASC'; $stmt = $db->prepare("SELECT field from table WHERE column = :my_param ORDER BY :order :direction"); $stmt->bindParam(':my_param', $is_live, PDO::PARAM_STR); $stmt->bindParam(':order', $order, PDO::PARAM_STR); $stmt->bindParam(':direction', $direction, PDO::PARAM_STR); $stmt->execute(); The :my_param works, but not :order or :direction. Is it not being internally escaped correctly? Am I stuck inserting it directly in the SQL? Like so: $order = 'columnName'; $direction = 'ASC'; $stmt = $db->prepare("SELECT * from table WHERE is_live = :is_live ORDER BY $order $direction"); Is there a PDO::PARAM_COLUMN_NAME constant or some equivalent? Thanks!

    Read the article

  • IIS + PHP Data Objects + MS SQL?

    - by jldugger
    We're migrating an LAOP server to Win 2k8 IIS7 MSSQL and PHP (WIMP?) at work, and I'm using the opportunity to clean up the PHP. Currently it doesn't use PDO, and I'd like to rewrite the PHP to use that instead. Challenge is, I don't know much about MSSQL and PHP deployment on Windows. The official MSSQL PDO object is experimental / depreicated and recommends PDO-ODBC. Microsoft just announced a driver supporting PDO. Is there no other PDO driver? How does SQLSRV contrast with PDO-ODBC?

    Read the article

  • Why does this pdo::mysql code crash on windows??

    - by user154107
    Why does this pdo::mysql code crash on windows??? <?php $username = "root"; $password = ""; try { $dsn = "mysql:host=localhost;dbname=employees"; $dbh = new PDO($dsn, $username, $password); $dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo "Connected to database<br />" ; $dbh->exec("DROP TABLE IF EXISTS vCard;"); $dbh->exec("DROP TABLE IF EXISTS emp;"); $table = "CREATE TABLE vCard( id INT(4) NOT NULL PRIMARY KEY, firstName VARCHAR (255), lastName VARCHAR (255), office VARCHAR (255), homePh VARCHAR (13), mobilePh VARCHAR (13))"; $dbh->exec($table); $dbh->beginTransaction(); $dbh->exec("INSERT INTO vCard(id, firstName, lastName, office, homePh, mobilePh) VALUES (4834, 'Randy', 'Lewis', 'SR. Front End Developer', '631-842-3375', '917-435-2245');"); $dbh->exec("INSERT INTO vCard(id, firstName, lastName, office, homePh, mobilePh) VALUES (0766, 'Frank', 'LaGuy', 'Graphic Designer', '631-789-8244', '917-324-9897');"); $dbh->exec("INSERT INTO vCard(id, firstName, lastName, office, homePh, mobilePh) VALUES (6684, 'Donnie', 'Dolemite', 'COO', '631-789-9482', '917-234-1222');"); $dbh->exec("INSERT INTO vCard(id, firstName, lastName, office, homePh, mobilePh) VALUES (8569, '', 'McLovin', 'Actor', '631-842-9786', '917-987-8944');"); $dbh->commit(); echo "Data entered successfully<br/><br/>"; $sql = "SELECT * FROM vCard"; // WHERE firstName = 'Donnie'"; $results = $dbh->query($sql); foreach ($results as $id){ echo "SSN: ". $id['id']." "; echo "First Name: ". $id['firstName']." "; echo "Last Name: ". $id['lastName']."<br/>"; } } catch (PDOException $e) { echo "Failed: " . $e->getMessage(); $dbh->rollback(); } ?> basically this line of code is what triggers Apache to crash.. $sql = "SELECT * FROM vCard"; If I try to select one value like 'id' it'll ... when I try to select more than one value "*" it crashes??????

    Read the article

  • How do check if PDO object is connected properly inside a different class?

    - by tgun926
    I want to fetch some information from my mysql database in a class, so I'm passing in the PDO object into a __construct function, and working from there. However, what's an elegant way of checking to see if the PDO object was correctly created, and that the connection is open when the Table class is instantiated? class Table{ public function __construct(PDO $db, $week){ try{ $query = $db -> query ("SELECT * FROM `table1` where `day` = 'monday'"); } catch(PDOExeption $e){ echo 'error: '. $e->getMessage(); //die(); } } } I don't think this code does what I want.

    Read the article

  • Using PDO with MVC

    - by mister martin
    I asked this question at stackoverflow and received no response (closed as duplicate with no answer). I'm experimenting with OOP and I have the following basic MVC layout: class Model { // do database stuff } class View { public function load($filename, $data = array()) { if(!empty($data)) { extract($data); } require_once('views/header.php'); require_once("views/$filename"); require_once('views/footer.php'); } } class Controller { public $model; public $view; function __construct() { $this->model = new Model(); $this->view = new View(); // determine what page we're on $page = isset($_GET['view']) ? $_GET['view'] : 'home'; $this->display($page); } public function display($page) { switch($page) { case 'home': $this->view->load('home.php'); break; } } } These classes are brought together in my setup file: // start session session_start(); require_once('Model.php'); require_once('View.php'); require_once('Controller.php'); new Controller(); Now where do I place my database connection code and how do I pass the connection onto the model? try { $db = new PDO('mysql:host='.DB_HOST.';dbname='.DB_DATABASE.'', DB_USERNAME, DB_PASSWORD); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch(PDOException $err) { die($err->getMessage()); } I've read about Dependency Injection, factories and miscellaneous other design patterns talking about keeping SQL out of the model, but it's all over my head using abstract examples. Can someone please just show me a straight-forward practical example?

    Read the article

  • How to get PHP command line to work with PDO?

    - by Sabya
    I want to work with PDO, through PHP command line. It works perfect through the PHP web API, but not through the command line. But when I execute the command: php test.php, it says unknown class PDO. I think it has something to do with the thread-safety difference. Because, when I execute the above command, the following warnings come: - F:\shema\htdocs>php test.php PHP Warning: PHP Startup: soap: Unable to initialize module Module compiled with module API=20060613, debug=0, thread-safety=0 PHP compiled with module API=20060613, debug=0, thread-safety=1 These options need to match in Unknown on line 0 PHP Warning: PHP Startup: sockets: Unable to initialize module Module compiled with module API=20060613, debug=0, thread-safety=0 PHP compiled with module API=20060613, debug=0, thread-safety=1 These options need to match in Unknown on line 0 PHP Warning: PHP Startup: mysql: Unable to initialize module Module compiled with module API=20060613, debug=0, thread-safety=0 PHP compiled with module API=20060613, debug=0, thread-safety=1 These options need to match in Unknown on line 0 PHP Warning: PHP Startup: pdo_mysql: Unable to initialize module Module compiled with module API=20060613, debug=0, thread-safety=0 PHP compiled with module API=20060613, debug=0, thread-safety=1 These options need to match in Unknown on line 0 PHP Warning: PHP Startup: pdo_pgsql: Unable to initialize module Module compiled with module API=20060613, debug=0, thread-safety=0 PHP compiled with module API=20060613, debug=0, thread-safety=1 These options need to match in Unknown on line 0 PHP Fatal error: Class 'PDO' not found in F:\shema\htdocs\test.php on line 2 PHP version: 5.2.9-2, downloaded from here. OS: Windows Vista If the problem is with the modules, where do I get the thread safe modules for those modules?

    Read the article

  • checking is username exists on two tables PHP PDO?

    - by PHPLOVER
    Me again. I have a users table and a users_banlist table. On my registration form i want to check all in one query whether the username someone entered on form exists in the users table and see if it also exists on the users_banlist table. I can do them on there own in individual queries but would rather do it all in one. Here is what i got, but even thou i enter a username that is taken it does not tell me its already taken. $stmt = $dbh->prepare(" SELECT users.user_login, users_banlist.user_banlist FROM users , users_banlist WHERE users.user_login = ? OR users_banlist.user_banlist = ?"); // checker if username exists in users table or users_banlist table $stmt->execute(array($username, $username)); if ( $stmt->rowCount() > 0 ) { $error[] = 'Username already taken'; } Basically i think it is something to do with the execute or rowCount(), could anyone tell me where i am going wrong ? being new to pdo im finding it a little confusing at the moment until i get my pdo book delivered to learn pdo. Thank you as always, phplover

    Read the article

  • PHP PDO: Fetching data as objects - properties assigned BEFORE __construct is called. Is this correc

    - by Erik
    The full question should be "Is this correct or is it some bug I can't count on?" I've been working with PDO more and in particular playing with fetching data directly into objects. While doing so I discovered this: If I fetch data directly into an object like this: $STH = $DBH->prepare('SELECT first_name, address from people WHERE 1'); $obj = $STH->fetchAll(PDO::FETCH_CLASS, 'person'); and have an object like this: class person { public $first_name; public $address; function __construct() { $this->first_name = $this->first_name . " is the name"; } } It shows me that the properties are being assigned before the __construct is being called -- because the names all have " is the name" appended. Is this some bug (in which case I can't/won't count on it) or is this The Way It Should Be. Because it's really quite a nice thing the way it works currently.

    Read the article

  • Are PDO prepared statements sufficient to prevent SQL injection?

    - by Mark Biek
    Let's say I have code like this: $dbh = new PDO("blahblah"); $stmt = $dbh->prepare('SELECT * FROM users where username = :username'); $stmt->execute( array(':username' => $_REQUEST['username']) ); The PDO documentation says The parameters to prepared statements don't need to be quoted; the driver handles it for you. Is that truly all I need to do to avoid SQL injections? Is it really that easy? You can assume MySQL if it makes a difference. Also, I'm really only curious about the use of prepared statements against SQL injection. In this context, I don't care about XSS or other possible vulnerabilities.

    Read the article

  • PDO Statement moving away from mysql_connect [on hold]

    - by user3555680
    Can someone please help me write a simple query "SELECT first_name FROM table_name" using PDO. I want to move away from using mysql_connect. Im working on a php project with mysql. Can you please write for me such a code that i can use THANK YOU <?php $host="127.0.0.1"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="microict-intrasys"; // Database name //$id = 5; try { $conn = new PDO('mysql:host={$host};dbname={$db_name}', $username, $password); // you neeeeeed this--^ and this--^ $stmt = $conn->prepare('SELECT version FROM system_info'); $stmt->execute(array('id' => $id)); $result = $stmt->fetchAll(); if ( count($result) ) { foreach($result as $row) { print_r($row); } } else { echo "No rows returned."; } } catch(PDOException $e) { echo 'ERROR: ' . $e->getMessage(); } ?>

    Read the article

  • sqlite ERROR no such column

    - by Richard
    Hi, Does anyone here have some experience with this error? Only If I use the WHERE clause, I get this error. I use php PDO to get the results. And this is my simple table $sql = "CREATE TABLE samenvatting ( stem_id INTEGER PRIMARY KEY AUTOINCREMENT, poll_id TEXT, stem_waarde_id TEXT, totaal INTEGER )"; $crud->rawQuery($sql); $poll_id = "somepoll"; $records = $crud->rawSelect('SELECT * FROM samenvatting WHERE poll_id=´.$poll_id); pdo abstract class public function conn() { isset($this->username); isset($this->password); if (!$this->db instanceof PDO) { $this->db = new PDO($this->dsn, $this->username, $this->password); $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } } public function rawSelect($sql) { $this->conn(); return $this->db->query($sql); } Thanks, Richard

    Read the article

  • PDOStatement::bindParam() not setting AI value from MySQL insert?

    - by Alan
    I have a simple insert statement using PDO php class. $statement = $db->prepare('INSERT INTO demographics (id,location_id,male,ethnicity_id,birthyear) VALUES (:id,:location_id,:male,:ethnicity_id,:birthyear)'); $statement->bindParam(':id',$demo->id,PDO::PARAM_INT,4); $statement->bindParam(':location_id', $demo->locationid,PDO::PARAM_INT); $statement->bindParam(':male',$demo->male,PDO::PARAM_BOOL); $statement->bindParam(':ethnicity_id',$demo->ethnicityid,PDO::PARAM_INT); $statement->bindParam(':birthyear',$demo->birthyear,PDO::PARAM_INT); $statement->execute(); print_r($demo); Even though the statement executes correctly (row is correctly written), $demo-id is null. Any thoughts?

    Read the article

  • How to insert array into mysql using PDO and bindParam?

    - by moomoochoo
    I'm using the following code. The code works, but I want to change it so that it uses bindparam try { $dbh = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password); $stqid=array(); for ($i=0; $i<$array_count; $i++){ $stqid[$i][0]=$lastInsertValue; $stqid[$i][1]=$qid[$i][0]; $stqid[$i][2]=$qid[$i][1]; } $values = array(); foreach ($stqid as $rowValues) { foreach ($rowValues as $key => $rowValue) { $rowValues[$key] = $rowValues[$key]; } $values[] = "(" . implode(', ', $rowValues) . ")"; } $count = $dbh->exec("INSERT INTO qresults(instance, qid, result) VALUES ".implode (', ', $values)); $dbh = null; } catch(PDOException $e){ echo $e->getMessage(); } I replaced the following $count = $dbh->exec("INSERT INTO qresults(instance, qid, result) VALUES ".implode (', ', $values)); with $sql = "INSERT INTO qresults (instance, qid, result) VALUES (:an_array)"; $stmt = $dbh->prepare($sql); $stmt->bindParam(':an_array', implode(',', $values),PDO::PARAM_STR); $stmt->execute(); but the insert doesn't work anymore (I didn't get any error messages though). QUESTION: What am I doing wrong? How can I rewrite the code to use bindParam?

    Read the article

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