Seminar chu 5
Download
1 / 8

Seminar Chủ Đề 5 - PowerPoint PPT Presentation


  • 72 Views
  • Uploaded on

Seminar Chủ Đề 5. Kết Nối CSDL V ơ ́i Ngôn Ngữ PHP. Group 30: _OrNothing. 0512212 Nguyễn Duy Lộc 0512226 Nguyễn Thanh Nam 0512240 Nguyễn Thị Kim Ngân 0512289 Phạm Tú San. Thao tác với các HQT CSDL khác. Với Microsoft SQL Server Với Microsoft Access – Sử dụng OBDC

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Seminar Chủ Đề 5' - mercer


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Seminar chu 5

Seminar Chủ Đề 5

Kết Nối CSDL Với Ngôn Ngữ PHP

Group 30: _OrNothing.

0512212 Nguyễn Duy Lộc

0512226 Nguyễn Thanh Nam

0512240 Nguyễn Thị Kim Ngân

0512289 Phạm Tú San


Thao ta c v i ca c hqt csdl kha c
Thao tác với các HQT CSDL khác

  • Với Microsoft SQL Server

  • Với Microsoft Access – Sử dụng OBDC

  • Với Microsoft Access - Sử dụng ADO

  • Với Oracle –

  • Với …


Thao ta c v i microsoft sql server
Thao Tác với Microsoft SQL Server

<?php

//1.Ket Noi CSDL

$connection = mssql_connect(“hostname”,”username”,”password”);

mssql_select_db(“database_name”,$connection);

//2.Chuan bi cau truy van va 3.Thuc thi cau truy van

$strSQL = “select * from TableName”;

$result = mssql_query($strSQL);

//4.Xu ly du lieu tra ve

While ($row = mssql_fetch_array($result))

{

for ($i=0; $i<mssql_num_fields($result); $i+)

echo $row[$i].””;

}

//5.Dong ket noi

mssql_close($connection);

?>


Thao ta c v i microsoft sql server vi du
Thao Tác với Microsoft SQL Server - Ví Dụ

While ($row = mssql_fetch_array($result))

{

echo $row['MaHocVien']; echo " - ";

echo $row['TenHocVien']; echo " - ";

echo $row['Diachi']; echo " - ";

echo $row['DienThoai'];

/* for ($i=0; $i<mssql_num_fields($result); $i++)

{

echo $row[$i]; echo "-";

} */

print "<br>";

}

mssql_close($con);

?>

</body>

</html>

<html>

<body>

<?php

$db_name = "TestDB";

$table_name ="HOCVIEN";

@$con=mssql_connect(".","sa","")

or die(mssql_error());

mssql_select_db($db_name,$con)

or die(mssql_error());

$strSQL = "select * from $table_name";

$result = mssql_query($strSQL);


V i microsoft access s du ng obdc
Với Microsoft Access – Sử dụng OBDC

<?php

//1.Ket Noi CSDL

$connection = odbc_connect(“mobileDB”,””,””);

//2.Chuan bi cau truy van va 3.Thuc thi cau truy van

$strSQL = “select * from TableName”

$result = odbc_exec($connection,$strSQL);

//4.Xu ly du lieu tra ve

While ($row = odbc_fechc_row($result))

{

for ($i=0; $i<odbc_num_fields($result); $i++)

echo odbc_result($result,$i).””;

}

//5.Dong ket noi

odbc_close($connection);

?>


V i microsoft access s du ng obdc vi du
Với Microsoft Access – Sử dụng OBDC – Ví Dụ

<html>

<body>

<?php

$db_name = "Database";

$table_name ="KhachHang";

$conn=odbc_connect($db_name,'','');

if (!$conn)

{exit("Connection Failed: “. $conn);}

$sql="SELECT * FROM $table_name";

$rs=odbc_exec($conn,$sql);

if (!$rs)

{exit("Error in SQL");}

echo "<font color='red'> Ten Khach Hang<br/> </font>";

while (odbc_fetch_row($rs))

{

$name=odbc_result($rs,"HoTen");

echo "<font color='blue'>$name<br/> </font>";

}

odbc_close($conn);

?>

</body>

</html>


V i microsoft access s du ng ado
Với Microsoft Access – Sử dụng ADO

<?php

//1.Ket Noi CSDL

$db= “db/BookStoreDB.mdb”;

$conn = new COM(“ADODB.connection”);

$sql = “DRIVER = {Microsoft Access Drive(*.mdb)};

DBQ=“.realpath($db).”;uid=;pwd=;”;

$conn->open($sql);

//2.Chuan bi cau truy van va 3.Thuc thi cau truy van

$strSQL = “select * from TableName”

$result = $conn->execute($strSQL);

//4.Xu ly du lieu tra ve

While(!$rs->EOF)

{

echo $rs->Fields[‘FieldsName’]->Value.””;

$rs->MoveNext();

}

//5.Dong ket noi

$rs->close();

$conn->close();

?>


Q&A

Tài Liệu Tham Khảo:

1. www.w3schools.com/php

2. New_Riders_-_Php_Functions_Essential_Reference

3. PHP_5_Fast_Easy_Web_Development


ad