Turning VB into PHP
Moderator: General Moderators
Turning VB into PHP
Hello all
I was just wondering how would a person go about altering some VB code to PHP? I have a stored procedure written in VB but my client wants only PHP. Is there anyone who could point me in the right direction?
Thanks
I was just wondering how would a person go about altering some VB code to PHP? I have a stored procedure written in VB but my client wants only PHP. Is there anyone who could point me in the right direction?
Thanks
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: Turning VB into PHP
You have to rewrite the code or search Google for a converter, but honestly they always suck and it's often easier to just rewrite from scratch using the existing code as a template. You can easily convert functions over to PHP and a stored procedure, you could probably do the same and make it MySQL instead of MSSQL.
Re: Turning VB into PHP
It probably won't be too complicated either. The PHP version will probably consist of substantially less code.
Re: Turning VB into PHP
vb or vbscript?
Re: Turning VB into PHP
Can you post some code for us to take a look at? We may be able to give you some more direct help then.
Re: Turning VB into PHP
Thanks all for your help so far.
Below is the code that I need to change from VB into PHP. The code is taken from http://www.xcri.org/wiki/index.php/Samp ... parameters.
What it should do is turn the course data in the MSSQL database as XML. One other thing that I would like to do is also save the output to the root folder of web server which again I have not quite figured out how to achieve.
Below is the code that I need to change from VB into PHP. The code is taken from http://www.xcri.org/wiki/index.php/Samp ... parameters.
What it should do is turn the course data in the MSSQL database as XML. One other thing that I would like to do is also save the output to the root folder of web server which again I have not quite figured out how to achieve.
Code: Select all
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Tavis Reddick, Adam Smith College
-- Create date: 2009-08-03
-- Modified date: 2010-03-13
-- Description: Returns XCRI course feeds from a greatly simplified course database.
-- Licence: This work is licensed under the Creative Commons Attribution 3.0 Unported License.
-- To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or send a
-- letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
-- =============================================
CREATE PROCEDURE [dbo].[usp_CourseFeed]
-- Add the parameters for the stored procedure here
@schemaName NVARCHAR(25) = 'XCRI CAP 1.1', -- in future, add new feed for 'XCRI CAP 1.2'.
@providerIdentifier NVARCHAR(25) = '0000X00XX0', -- your organizational identifier
@providerName NVARCHAR(50) = 'Acme University' -- your organizational name
AS
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SET CONCAT_NULL_YIELDS_NULL OFF; -- So null values can be concatenated with strings.
IF @schemaName = 'XCRI CAP 1.0'
BEGIN
-- Build the XCRI CAP 1.0 XML using correlated subqueries with FOR XML PATH.
WITH XMLNAMESPACES ('http://xcri.org/profiles/catalog' AS xcri,
'http://www.w3.org/1999/xhtml' AS xhtml,
'http://purl.org/dc/elements/1.1/' AS dc,
DEFAULT 'http://xcri.org/profiles/catalog')
SELECT GETDATE() AS "@generated",
CAST ((SELECT @providerIdentifier AS identifier, @providerName AS [name],
CAST ((SELECT CourseId AS identifier, (LTRIM(QualificationName + ' ') + Title) AS title,
CONVERT(XML, '<div xmlns="http://www.w3.org/1999/xhtml">' + CAST(Overview AS NVARCHAR(4000)) + '</div>') AS [description], -- wrap the Overview XML fragment in a div with the appropriate HTML namespace.
COALESCE(QualificationName, '') AS "qualification/title", COALESCE(QualificationLevel, 0) AS "qualification/level", -- qualification can't be empty, so use COALESCE to put empty strings or zeroes in if columns contain null values.
CAST((SELECT ProgrammeId AS identifier, StartDate AS start, ModeOfAttendance AS studyMode
FROM dbo.Programme AS programme WHERE course.CourseId = programme.CourseId
FOR XML PATH('presentation'), ELEMENTS) AS XML)
, SubjectArea AS "dc:subject"
FROM dbo.Course AS course
FOR XML PATH ('course')) AS XML)
FOR XML PATH ('provider')) AS XML)
FOR XML PATH ('catalog')
END
IF @schemaName = 'XCRI Curriculum 1.0'
BEGIN
-- Build the XCRI CAP 1.0 XML using correlated subqueries with FOR XML PATH.
WITH XMLNAMESPACES ('http://elframework.org/curriculum/elements' AS xcri,
'http://www.w3.org/1999/xhtml' AS xhtml,
'http://purl.org/dc/elements/1.1/' AS dc,
'http://www.imsglobal.org/services/rli/xsd/imsRLIManDataSchema_v1p0' AS imsRLI,
DEFAULT 'http://elframework.org/curriculum/elements')
SELECT 'Date/time of data extract' AS [calendarEvent/dc:title], GETDATE() AS [calendarEvent/dc:date],
CAST ((SELECT 'course' AS [@type], CourseId AS identifier, (LTRIM(QualificationName + ' ') + Title) AS [dc:title],
SubjectArea AS "dc:subject",
CONVERT(XML, '<div xmlns="http://www.w3.org/1999/xhtml">' + CAST(Overview AS NVARCHAR(4000)) + '</div>') AS [description], -- wrap the Overview XML fragment in a div with the appropriate HTML namespace.
COALESCE(QualificationName, '') AS [recognitions/recognition/award/awardTitle], COALESCE(QualificationLevel, 0) AS [recognitions/recognition/award/awardLevel], -- qualification can't be empty, so use COALESCE to put empty strings or zeroes in if columns contain null values.
CAST ((SELECT
CAST((SELECT ProgrammeId AS identifier, ModeOfAttendance AS studyMode,
StartDate AS start, EndDate AS [end], Venue AS location
FROM dbo.Programme AS programme WHERE course.CourseId = programme.CourseId
FOR XML PATH('offering'), ELEMENTS, ROOT('offerings')) AS XML)
FOR XML PATH('offeringPattern')) AS XML)
FROM dbo.Course AS course
FOR XML PATH ('spec')) AS XML)
FOR XML PATH ('curriculum')
END;
IF @schemaName = 'XCRI CAP 1.1'
BEGIN
-- Build the XCRI CAP 1.1 XML using correlated subqueries with FOR XML PATH.
WITH XMLNAMESPACES ('http://xcri.org/profiles/catalog/terms' AS xcriTerms,
'http://xcri.org/profiles/catalog' AS xcri,
'http://www.w3.org/1999/xhtml' AS xhtml,
'http://www.w3.org/2001/XMLSchema-instance' AS xsi,
DEFAULT 'http://xcri.org/profiles/catalog')
SELECT GETDATE() AS "@generated", 'http://xcri.org/profiles/catalog/terms http://www.xcri.org/bindings/xcri_cap_terms_1_1.xsd' AS "@xsi:schemaLocation",
CAST ((SELECT @providerIdentifier AS identifier, @providerName AS title,
CAST ((SELECT CourseId AS identifier, (LTRIM(QualificationName + ' ') + Title) AS title, SubjectArea AS "subject",
CAST ((SELECT 'xcriTerms:aim' AS "@xsi:type",
CONVERT(XML, '<div xmlns="http://www.w3.org/1999/xhtml">' + CAST(Overview AS NVARCHAR(4000)) + '</div>')-- wrap the Overview XML fragment in a div with the appropriate HTML namespace.
FOR XML PATH ('description'), ELEMENTS) AS XML),
COALESCE(QualificationName, '') AS "qualification/title", COALESCE(QualificationLevel, 0) AS "qualification/level", -- qualification can't be empty, so use COALESCE to put empty strings or zeroes in if columns contain null values.
CAST((SELECT ProgrammeId AS identifier, StartDate AS start, ModeOfAttendance AS studyMode
FROM dbo.Programme AS programme WHERE course.CourseId = programme.CourseId
FOR XML PATH('presentation'), ELEMENTS) AS XML)
FROM dbo.Course AS course
FOR XML PATH ('course')) AS XML)
FOR XML PATH ('provider')) AS XML)
FOR XML PATH ('catalog')
END;
Last edited by Benjamin on Tue Apr 27, 2010 12:10 pm, edited 1 time in total.
Reason: Added [syntax=vb] tags.
Reason: Added [syntax=vb] tags.
Re: Turning VB into PHP
Hi,
I'm going to take a bit more of a look later, but here's the gist of my basic observation.
1. You're just writing XML, so things get much simpler to a certain extent; all we need to do is produce the valid XML by sticking a bunch of strings together. PHP does not need casting, and the database query can result in an array for easy reading.
2. file_put_contents() will dump our resulting string to a file.
3. Now a question... can I go under the assumption that we already have a database object, say, $myDB ?
I'm going to take a bit more of a look later, but here's the gist of my basic observation.
1. You're just writing XML, so things get much simpler to a certain extent; all we need to do is produce the valid XML by sticking a bunch of strings together. PHP does not need casting, and the database query can result in an array for easy reading.
2. file_put_contents() will dump our resulting string to a file.
3. Now a question... can I go under the assumption that we already have a database object, say, $myDB ?
Re: Turning VB into PHP
@garteth- I recommend that you put
around your code so it stands out more.[syntax]your code here[/syntax]
Re: Turning VB into PHP
On a whim, I did a Google....
Do these pages help you?
http://www.dynamicdrive.com/forums/show ... hp?t=14165
http://php.net/manual/en/class.domdocument.php
http://devzone.zend.com/article/1713
Do these pages help you?
http://www.dynamicdrive.com/forums/show ... hp?t=14165
http://php.net/manual/en/class.domdocument.php
http://devzone.zend.com/article/1713
Re: Turning VB into PHP
Your code sample is apparently a database stored procedure, not vb, and it shouldn't matter if you call the sp from vb or php or whatever other program language.