0

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?

1 Answer 1

2

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:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.