![]() If your table has columns ID and NAME, then $row will be hash ref with keys ID and NAME. First of all you can retrieve a row of data: my $row = $sth->fetchrow_hashref() This statement handle can be used for multiple things. If you want to retrieve results, you need to create a so-called statement handle with: $sth = $dbh->prepare("SELECT * FROM $table") See "DATABASE HANDLES" below for more details on database handles. In which case the quote method is executed automatically. An alternative approach is $dbh->do("INSERT INTO foo VALUES (?, ?)", undef, See DBI for details on the quote and do methods. Once you have connected to a database, you can execute SQL statements with: my $query = sprintf("INSERT INTO foo VALUES (%d, %s)", Perl returns a database handle to the connect method like so: $dbh = DBI->connect("DBI:mysql:database=$db host=$host", Two types of objects are available: database handles and statement handles. ![]() See "EXAMPLE" for a simple example above.įrom perl you activate the interface with the statement use DBI Īfter that you can connect to multiple MySQL database servers and send multiple queries to any of them via a simple object oriented interface. For installation, see the separate document DBD::mysql::INSTALL. In what follows we first discuss the use of DBD::mysql, because this is what you will need the most. Some rarely used functions are missing, mainly because no-one ever requested them. Most functions provided by this programming API are supported. In other words: DBD::mysql is an interface between the Perl programming language and the MySQL programming API that comes with the MySQL relational database management system. While (my $ref = $sth->fetchrow_hashref()) \n" ĭBD::mysql is the Perl5 Database Interface driver for the MySQL database. $sth->execute('Eggers') or die "execution failed: $dbh->errstr()" ![]() Or die "prepare statement failed: $dbh->errstr()" 'SELECT id, first_name, last_name FROM authors WHERE last_name = ?') My $dbh = DBI->connect($dsn, $user, $password) ![]() My $dsn = "DBI:mysql:database=$database host=$hostname port=$port"
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |