lolooza Posted May 24, 2012 Share Posted May 24, 2012 I'm new to php and my code looks like this: function addFistPages($numPages, $templateId){ $dsn = 'mysql:host='.DATABASE_SERVER.';port='.SERVER_PORT.';dbname='.DATABASE_NAME.''; $options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',); $pdo = new PDO($dsn, DATABASE_USERNAME, DATABASE_PASSWORD); $stmt = $pdo->query('SET FOREIGN_KEY_CHECKS = 0'); $stmt = $pdo->prepare("insert into page_template (template_id) values ('{$templateId}')"); $page = $pdo->prepare("select id, thumb, template_id as templateId, background_id as backgroundId from page_template where id = ?"); $tmp = array(); for ($i = 1; $i <= $numPages; $i++) { $stmt->execute(); $lastId = $pdo->lastInsertId(); $page->execute(array($lastId)); $tmp[] = $page->fetchObject('PageTemplateVO'); } return $tmp; } It seems like $page query selecting only id and thumb fields instead id, thumb, template_id and background_id. Can someone help me with this problem? what i'm doing wrong? Thanks in advance. Sorry for my english. Quote Link to comment https://forums.phpfreaks.com/topic/263046-pdo-help-needed/ Share on other sites More sharing options...
kicken Posted May 24, 2012 Share Posted May 24, 2012 Your other fields besides template_id would all be NULL unless you have some default clauses on your columns. The code doesn't really make much sense though, maybe explain what your attempting to do? Quote Link to comment https://forums.phpfreaks.com/topic/263046-pdo-help-needed/#findComment-1348275 Share on other sites More sharing options...
lolooza Posted May 24, 2012 Author Share Posted May 24, 2012 Your other fields besides template_id would all be NULL unless you have some default clauses on your columns. The code doesn't really make much sense though, maybe explain what your attempting to do? i'm trying to create new fields and get them with default values. but somehow this query "select id, thumb, template_id as templateId, background_id as backgroundId from page_template where id = ?" returns me only 'id' and 'thumb' fields. fileds "template_id" and "background_id " are foreign keys to another tables which are empty. "template_id" and "background_id " has default values, but i keep getting 2 fields ('id' and 'thumb' ) instead of 4 ('id' , 'thumb', 'template_id' , 'background_id ' ). Is it make more sence now? kicken thanks for replying. Quote Link to comment https://forums.phpfreaks.com/topic/263046-pdo-help-needed/#findComment-1348313 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.