Jump to content

PDO help needed


lolooza

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/263046-pdo-help-needed/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/263046-pdo-help-needed/#findComment-1348313
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.