DB_Table:

From: Date: Fri, 02 Feb 2007 21:17:00 +0000
Subject: DB_Table:
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-26488@lists.php.net to get a copy of this message
I am trying to follow the example in documentation for DB_Table and am having trouble. Here's my table: CREATE TABLE news ( news_id varchar(32) NOT NULL default '', title varchar(100) NOT NULL default '', article varchar(100) NOT NULL default '', PRIMARY KEY (news_id) ) My news_id is, by habit, created a random_gen function which is why it's varchar(32). Here's my class: <?php class news extends DB_Table { var $col = array( // unique row ID 'news_id' => array( 'type' => 'varchar', 'require' => 32 ), // first name 'title' => array( 'type' => 'varchar', 'size' => 100 ), // last name 'article' => array( 'type' => 'text' ) ); var $idx = array( 'news_id' => array( 'type' => 'unique', 'cols' => 'news_id' ) ); var $sql = array( // multiple rows for a list 'list' => array( 'select' => "news_id, title, article", 'order' => 'title DESC' ), // one row for an item detail 'item' => array( 'select' => 'news_id, title, article', 'get' => 'row' ), ); } ?> Here's my calling script: <?php // basic classes require_once 'MDB2.php'; require_once 'DB/Table.php'; require_once 'news.php'; // create a PEAR DB object $mdb2 =& MDB2::connect('mysql://username:password@localhost/database'); // set up for the Guestbook and create it $table = "news"; $auto_create = 'safe'; $book =& new admin_news($mdb2, $table, $auto_create); echo "<pre>"; // print out results if ($book->error) { echo "Failure! Try again."; print_r($book->error); } else { echo "Success!"; $cols_vals = array( 'news_id' => '6f25b278224a8bea9ff2e2d03c4ab621', 'title' => 'title skjkjiief jned kfueifh kjbdf', 'article' => 'sdlfh owehf jbsd kvjubw euof kjb sjbf kbj' ); $result = $book->insert($cols_vals); print_r($result); } ?> And here's what is displayed: Success!pear_error Object ( [error_message_prefix] => [mode] => 1 [level] => 1024 [code] => -6 [message] => Insert data not valid for column 'news_id' ('6f25b278224a8bea9ff2e2d03c4ab621') [userinfo] => [backtrace] => Array ( [0] => Array ( [file] => C:\pear\PEAR.php [line] => 572 [function] => pear_error [class] => pear_error [type] => -> [args] => Array ( [0] => Insert data not valid for column 'news_id' ('6f25b278224a8bea9ff2e2d03c4ab621') [1] => -6 [2] => 1 [3] => 1024 [4] => ) ) [1] => Array ( [file] => C:\pear\PEAR.php [line] => 595 [function] => raiseerror [class] => pear [type] => :: [args] => Array ( [0] => Insert data not valid for column 'news_id' ('6f25b278224a8bea9ff2e2d03c4ab621') [1] => -6 [2] => [3] => [4] => ) ) [2] => Array ( [file] => C:\pear\DB\Table.php [line] => 673 [function] => throwerror [class] => pear [type] => :: [args] => Array ( [0] => Insert data not valid for column 'news_id' ('6f25b278224a8bea9ff2e2d03c4ab621') [1] => -6 ) ) [3] => Array ( [file] => C:\pear\DB\Table.php [line] => 1614 [function] => throwerror [class] => news [type] => -> [args] => Array ( [0] => -6 [1] => 'news_id' ('6f25b278224a8bea9ff2e2d03c4ab621') ) ) [4] => Array ( [file] => C:\pear\DB\Table.php [line] => 1523 [function] => validinsert [class] => news [type] => -> [args] => Array ( [0] => Array ( [news_id] => 6f25b278224a8bea9ff2e2d03c4ab621 [title] => title skjkjiief jned kfueifh kjbdf [article] => sdlfh owehf jbsd kvjubw euof kjb sjbf kbj ) ) ) [5] => Array ( [file] => C:\site\index.php [line] => 27 [function] => insert [class] => news [type] => -> [args] => Array ( [0] => Array ( [news_id] => 6f25b278224a8bea9ff2e2d03c4ab621 [title] => title skjkjiief jned kfueifh kjbdf [article] => sdlfh owehf jbsd kvjubw euof kjb sjbf kbj ) ) ) ) [callback] => ) ____________________________________________________________________________________ The fish are biting. Get more visitors on your site using Yahoo! Search Marketing. http://searchmarketing.yahoo.com/arp/sponsoredsearch_v2.php

« previous php.pear.general (#26488) next »