Cemal
Cemal

Reputation: 1

write data from MySQL database

I have been programming with asp for years now but I am very new to php.

I want to pull the data from the mysql database I created.

If I was to do the same job with asp;

<%
    Set ObjConn = CreateObject("ADODB.Connection")
    ObjConn.Open ("DRIVER={SQL Server};SERVER=serveraddress;DATABASE=databasename;UID=username;PWD=password")

SQL = "SELECT * FROM PRODUCTS ORDER BY PRODUCTNAME DESC" 
    Set objProducts = objConn.Execute(SQL)

    Do While not objProducts.EOF 
%>
<%=objProducts("PRODUCTNAME")%>
<%
    objProducts.MoveNext 
    Loop
%>

How do I do same thing with php?

Upvotes: 0

Views: 67

Answers (1)

OMG Ponies
OMG Ponies

Reputation: 332521

Use:

<?php
  mysql_connect("serveraddress", "username", "password") or die("Could not connect: " . mysql_error());
  mysql_select_db("databasename");

  $result = mysql_query("SELECT PRODUCTNAME
                           FROM PRODUCTS 
                       ORDER BY PRODUCTNAME DESC");

  while ($row = mysql_fetch_array($result)) {
    echo $row["PRODUCTNAME"];
  }

  mysql_free_result($result);
?>

Recommendation

Never select columns that you will not use or display.

Reference:

Upvotes: 2

Related Questions