Min Yang Jung
November 13, 2008
 Open a connection
<?php
$dbhost = 'localhost';
$dbhost = 'db.php-mysql-tutorial.com:3306';
$dbuser = 'root';
$dbpass = '...
 Close a connection
<?php
// it does nothing but closing
// a mysql database connection
mysql_close($conn);
?>
 SELECT
<?php
include 'config.php';
include 'opendb.php';
$query = "SELECT name, subject, message FROM contact";
$result ...
 INSERT
<?php
include 'config.php';
include 'opendb.php';
mysql_select_db($mysql);
$query = "INSERT INTO user (host, user...
 Open a Connection
#!/usr/bin/perl
use Mysql;
print "Content-type: text/html nn";
$host = "localhost";
$database = "store...
 Close a Connection
# free result set
mysql_free_result($result);
# close the connection
mysql_close($connect);
?>
 SELECT
# DEFINE A MySQL QUERY
$myquery = "SELECT * FROM $tablename";
$execute = $connect->query($myquery);
$rownumber = ...
 INSERT
$myquery = "INSERT INTO $tablename (id, product,
quantity) VALUES (DEFAULT,'pineapples','15')";
$execute = $conne...
Upcoming SlideShare
Loading in …5
×

与 PHP 和 Perl 使用 MySQL 数据库

849 views

Published on

与 PHP 和 Perl 使用 MySQL 数据库

http://www.ossez.com/forum.php?mod=viewthread&tid=26891&fromuid=426
(出处: OSSEZ)

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
849
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

与 PHP 和 Perl 使用 MySQL 数据库

  1. 1. Min Yang Jung November 13, 2008
  2. 2.  Open a connection <?php $dbhost = 'localhost'; $dbhost = 'db.php-mysql-tutorial.com:3306'; $dbuser = 'root'; $dbpass = 'password'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'petstore'; mysql_select_db($dbname); ?>
  3. 3.  Close a connection <?php // it does nothing but closing // a mysql database connection mysql_close($conn); ?>
  4. 4.  SELECT <?php include 'config.php'; include 'opendb.php'; $query = "SELECT name, subject, message FROM contact"; $result = mysql_query($query); while($row = mysql_fetch_row($result)) { $name = $row[0]; $subject = $row[1]; $message = $row[2]; echo "Name :$name <br>" . "Subject : $subject <br>" . "Message : $row <br><br>"; }
  5. 5.  INSERT <?php include 'config.php'; include 'opendb.php'; mysql_select_db($mysql); $query = "INSERT INTO user (host, user, password, select_pr iv, insert_priv, update_ priv) VALUES ('localhost', 'phpcak e', PASSWORD('mypass'), 'Y', 'Y', 'Y')"; mysql_query($query) or die('Error, insert query failed'); $query = "FLUSH PRIVILEGES"; mysql_query($query) or die('Error, insert query failed'); include 'closedb.php‘ ?>
  6. 6.  Open a Connection #!/usr/bin/perl use Mysql; print "Content-type: text/html nn"; $host = "localhost"; $database = "store"; $tablename = "inventory"; $user = "username"; $pw = "password"; $connect = Mysql->connect($host, $database, $user, $pw); $connect->selectdb($database);
  7. 7.  Close a Connection # free result set mysql_free_result($result); # close the connection mysql_close($connect); ?>
  8. 8.  SELECT # DEFINE A MySQL QUERY $myquery = "SELECT * FROM $tablename"; $execute = $connect->query($myquery); $rownumber = $execute->numrows(); $fieldnumber = $execute->numfields(); # PRINT THE RESULTS print $rownumber."<br />"; print $fieldnumber."<br />";
  9. 9.  INSERT $myquery = "INSERT INTO $tablename (id, product, quantity) VALUES (DEFAULT,'pineapples','15')"; $execute = $connect->query($myquery); $affectedrows = $execute->affectedrows($myquery); $lastid = $execute->insertid($myquery); print $affectedrows."<br />"; print $lastid."<br />";

×