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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.