Working with MSSQL in PHP
10-16-2009, 09:54 AM
|
Working with MSSQL in PHP
|
Posts: 102
|
I have a procedure called "dbo.webCreateAcc", and I have no clue how to get it to be used threw PHP.
dbo.webCreateAcc
Code:
USE [ACCOUNT_DBF]
GO
/****** Object: StoredProcedure [dbo].[webCreateAcc] Script Date: 10/16/2009 08:39:37 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[webCreateAcc]
@account VARCHAR(15),
@password VARCHAR(36),
@birthday VARCHAR(120),
@email VARCHAR(120)
AS
SET NOCOUNT ON
DECLARE @DateActivated AS CHAR(8)
IF NOT EXISTS (SELECT account FROM ACCOUNT_TBL WHERE account = @account) BEGIN
INSERT INTO ACCOUNT_TBL (account, [password], id_no2, isuse, member, realname)
VALUES (@account, @password, @password, 'T', 'A', 'F')
SET @DateActivated = CONVERT(CHAR(8), GETDATE()-1, 112 ) --Is the date today - 1
--UPDATE ACCOUNT_TBL_DETAIL SET BlockTime = @DateYesterday WHERE account = @userid
--INSERT INTO ACCOUNT_TBL_DETAIL (account, gamecode, tester, m_chLoginAuthority, regdate, BlockTime, EndTime, WebTime, isuse)
-- VALUES (@account, 'A000', '2', 'F', GETDATE(), '20990101', '20990101', '20050101', 'O')
INSERT INTO ACCOUNT_TBL_DETAIL (account, gamecode, tester, m_chLoginAuthority, regdate, BlockTime, EndTime, WebTime, isuse, email, birthday)
VALUES (@account, 'A000', '2', 'F', GETDATE(), @DateActivated, '20990101', '20050101', 'O', @email, @birthday)
END
--ELSE BEGIN
--print '->Account exists = '
--print @account
--END
What would the PHP code look like to execute that?
|
|
|
|
10-16-2009, 10:36 AM
|
Re: Working with MSSQL in PHP
|
Posts: 22,260
Location: Blackpool. UK
|
|
|
|
|
10-16-2009, 11:12 AM
|
Re: Working with MSSQL in PHP
|
Posts: 102
|
I've read them before I posted. I still couldn't figure it out. Sigh.
|
|
|
|
10-16-2009, 12:11 PM
|
Re: Working with MSSQL in PHP
|
Posts: 3,176
Name: Thierry
Location: I'm the uber Spaminator !
|
taken straight from the php page, and just modified what you need:
PHP Code:
<?php // Connect to MSSQL mssql_connect('myServer', 'sa', 'saPwd'); mssql_select_db('myDb');
// Create a new statement $stmt = mssql_init('dbo.webCreateAcc', $link);
// Bind values here mssql_bind($stmt, '@account', 'MyAccount', SQLVARCHAR, false, false, 15); mssql_bind($stmt, '@password', 'MySuperPwd', SQLVARCHAR, false, false, 36); mssql_bind($stmt, '@birthday', '19750330', SQLVARCHAR, false, false, 120); mssql_bind($stmt, '@email', 'some@thing.com', SQLVARCHAR, false, false, 120);
// Once values are binded we execute our statement // using mssql_execute: mssql_execute($stmt);
// And we can free it like so: mssql_free_statement($stmt); ?>
And just because I'm a dba, I'll give you my sermon about using a varchar type for the birthdate, which is more than sub optimal.
I seriously hope you are not using a varchar field in your db too, but a datetime field...
__________________
Only a biker knows why a dog sticks his head out the window.
Last edited by tripy; 10-16-2009 at 12:15 PM..
|
|
|
|
10-16-2009, 12:24 PM
|
Re: Working with MSSQL in PHP
|
Posts: 102
|
Tripy, the birthday would be 3/30/1975 in your example right?
Also;
Code:
Fatal error: Only variables can be passed by reference in /usr/home/-/domains/-/public_html/modules/test1.php on line 73
Line 73
PHP Code:
mssql_bind($stmt, '@account', 'MyAccount', SQLVARCHAR, false, false, 15);
Everything is working fine, thank you.
Last edited by Aaron™; 10-16-2009 at 12:32 PM..
|
|
|
|
10-16-2009, 02:26 PM
|
Re: Working with MSSQL in PHP
|
Posts: 3,176
Name: Thierry
Location: I'm the uber Spaminator !
|
No, it would be the 30 of march 1975.
Ms sql server understand the YYYYMMDD syntax when it casts from varchar to datetime.
It might be dependant of the regional settings, though, I'm not 100% sure of that.
__________________
Only a biker knows why a dog sticks his head out the window.
|
|
|
|
10-16-2009, 10:05 PM
|
Re: Working with MSSQL in PHP
|
Posts: 102
|
Quote:
|
Everything is working fine, thank you.
|
dsadd
|
|
|
|
|
« Reply to Working with MSSQL in PHP
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|