useless thanks for your reply
config.php->
define( “DB_DSN”, “mysql:dbname=mydatabase” );
define( “DB_USERNAME”, “root” );
define( “DB_PASSWORD”, “mypass” );
dataobject.class.php->
protected function connect() {
try {
$conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
$conn- > setAttribute( PDO::ATTR_PERSISTENT, true );
$conn- > setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
} catch ( PDOException $e ) {
die( “Connection failed: “ . $e- > getMessage() );
}
return $conn;
}
extend dataobj comment.class.php->
public function insert() {
$conn = parent::connect();
$sql = “INSERT INTO “ . TBL_COMMENTS . “ (
comment
) VALUES (
:comment
)”;
try {
$st = $conn- > prepare( $sql );
$st- > bindValue( “:comment”, $this- > data[“comment”], PDO::PARAM_STR );
$st- > execute();
parent::disconnect( $conn );
} catch ( PDOException $e ) {
parent::disconnect( $conn );
die( “Query failed: “ . $e- > getMessage() );
}
}
comment.php->
$comment = new comment( array(
“comment” = > isset( $_POST[“comment”] ) ? preg_replace
( “/[^ \-\_a-zA-Z0-9]/”, “”, $_POST[“comment”] ) : “”,) );
$comment- > insert();
$id = mysql_insert_id("please help me");
displayThanks();
Last edited by manna; February 12th, 2012 at 02:36 PM..
|