PDA

View Full Version : Nhúng sql từ php



dieubuon
23-02-2004, 09:35
Anh em cho tui hỏi cái nẻ:
Hiện nay tui đang học sql ,và đã tạo ra được sql .Nhưng không biết nhúng nó vào PHP thề nào caTìm hiểu qua source của các file phpbb nhưng cũng chả hiểu gì cả .
Ai sành về cái nì giúp tui tay nào .

dokhanh
25-02-2004, 15:48
• Open a connection to the database vs. opening a stream to a file.
• Selecting the data to read/write with SQL queries vs. setting the file pointer.
• Reading and writing the data happens in both cases.
• Close the connection to the database vs. closing the stream to the file.

Here is a first little example, which already contains all important steps.

<html><body>
<?
$host = "localhost";
$user = "phpuser";
$pw = "";
$database = "phptest";

$dblink = mysql_connect($host, $user, $ps) or
die("Can not connect to db-server!");

mysql_select_db($database, $dblink);

$query = "SELECT name, nr FROM testtable ";

$result = mysql_query($query);

while($row = (mysql_fetch_row($result))) {
print("Name: " . $row[0]);
print(" nr: " . $row[1] . "<br>\n");
}

mysql_close($dblink);
?></body><html>