1 / 8

Seminar Chủ Đề 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 tác với các HQT CSDL khác. Với Microsoft SQL Server Với Microsoft Access – Sử dụng OBDC

mercer
Download Presentation

Seminar Chủ Đề 5

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. 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 …

  3. 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); ?>

  4. 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);

  5. 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); ?>

  6. 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>

  7. 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(); ?>

  8. 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

More Related