• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

adding fields to mySOL

Am connecting using the following...
<<CODE SNIPPET>>
$dsn = "DBI:$dbDriver:database=$dbName";
$db_handle = DBI->connect($dsn, $usrName, $dbPassword);
<<END CODE SNIPPET>>

How can I add fields to the db?

::StephenBlade

0
stephenblade
Asked:
stephenblade
  • 3
  • 2
1 Solution
 
malecCommented:
$dbh = DBI->connect("DBI:mysql:dbname", "usr", $pass) or
    die "unable to connect to the database: $DBI::errstr\n";

$wquery = qq( insert into addresses (name,email,tel) values (?,?,?));
$sth = $dbh->prepare($wquery) or die $dbh->errstr;
      $sth->execute($name,$email,$tel) or die $sth->errstr;

see full working demo @ www.perlnow.com script mysql
0
 
stephenbladeAuthor Commented:
How do I create the table "addresses"?

0
 
malecCommented:
create table addresses ( id integer not null auto increment, name VARCHAR(64), email VARCHAR(64), tel CHAR(16) );
0
 
stephenbladeAuthor Commented:
So what am I doing wrong? I just want to create the table right now..


$dsn = "DBI:$dbDriver:database=$dbName";

$db_handle = DBI->connect($dsn, $usrName, $dbPassword);

if( $db_handle )
{
print "connected";
create table registrations ( id integer not null auto increment, name VARCHAR(64), email VARCHAR(64), add1 CHAR(64), add2 CHAR(64), add3 CHAR(64), bids CHAR(600));
print "Tables Created";
 } else {
print "Error";
}

0
 
malecCommented:
see code above. 'create table' should be part of a query string that you define before preparing and executing a query.
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now