Jump to content

From .ASP recordsets to .PHP


TapeGun007

Recommended Posts

I need help converting something very simple from ASP (classic).

 

Here is the ASP code:

<% DO While NOT recordset.EOF %>
<tr><td colspan="3">Posted On: <%=recordset("NewsDate") %></td></tr>
(Populate a table from Access Database here)
<%
Recordset.MoveNext
Loop
%>

 

Basically, instead of using SQL to access the db, I used a recordset.  Why?  Because this is a memo field that stores news information.  In the news memo field, it stores apostrophies, and quotation marks.  Thus, using SQL to retrieve that information causes a problem on output.

 

What is the PHP equivalent?

 

As a recap, I have a memo field that stores lots of text with apostrophies and quotes.  I need to be able to pull the information out of the memo field without using SQL.  How can I do this?

 

 

Link to comment
https://forums.phpfreaks.com/topic/195764-from-asp-recordsets-to-php/
Share on other sites

ARG,  I should've posted what I already have:

 

$result = mysql_query("SELECT * FROM News WHERE ShowNews='Yes' ORDER BY News.NewsDate DESC , News.NewsID DESC");
    while($row = mysql_fetch_array($result))
    	{
	echo "<tr><td background='images/news_header.gif' class='ContentWhite'>  <b>".$row['NewsTitle']."<b></td><td background='images/news_date.gif'>".$row['NewsDate']."</td></tr>";
	echo "<tr><td background='images/news_main.gif' colspan='2'>".$row['News']."</td></tr>";
	echo "<tr><td colspan='2'><b>-".$row['NewsWriter']."</b></td></tr>";
	}

 

This is the output that I get:

�The breath isn�t that important.� 
�are you still reading? Good. Now let me explain my reasoning for saying such a blasphemous thing. 

 

See those funny characters?  They are quotes and apostrophies stored in $row['News'].  This is why in .asp I used recordsets instead of SQL to pull that information from the memo field.

See those funny characters?  They are quotes and apostrophies stored in $row['News'].  This is why in .asp I used recordsets instead of SQL to pull that information from the memo field.

 

A recordset is essentially the same thing as a result resource in php. Which is exactly what mysql_query() returns.

In .asp (classic) I used this code:

 

sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("\db\Choir.mdb") 
					Set recordset = Server.CreateObject("ADODB.Recordset")
					IF Request.QueryString("NewsID") <> "" THEN
						intID = Request.QueryString("NewsID")
						Recordset.Open "News", sConnString, 1,2,2
						Recordset.Filter = "NewsID = '" & intID & "'"
						Recordset("NewsDate") = Request.Form("fNewsDate")
						Recordset("NewsTitle") = Request.Form("fNewsTitle")
						Recordset("News") = Request.Form("fNews")
						Recordset("NewsWriter") = Request.Form("fNewsWriter")
						Recordset("ShowNews") = Request.Form("fShowNews")
						sMessage = "News Article Succesfully Updated!"

Check your database to see if it is encoded there.  I believe the database has those characters stored.  It looks to me you went from access db to mssql and that might be where the strange encoding happened.  Look into a way to sanitize your stored data if it is encoded with those characters.  PHP handles both ' and " appropriately by encoding them with a "\".

 

Collation is utf8_general_ci

 

Using MyPHPAdmin, I checked the data and cut and pasted right out of the db:

 

“The breath isn’t that important.”

<p>

…are you still reading? Good. Now let me explain my reasoning for saying such a blasphemous thing.

 

So... the data in there is fine.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.