Reply
Working with MSSQL in PHP
Old 10-16-2009, 09:54 AM Working with MSSQL in PHP
Super Talker

Posts: 102
Trades: 0
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?
Aaron™ is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 10-16-2009, 10:36 AM Re: Working with MSSQL in PHP
chrishirst's Avatar
Super Moderator

Posts: 22,260
Location: Blackpool. UK
Trades: 0
http://www.google.com/search?q=mssql...+procedure+php

http://www.php.net/manual/en/function.mssql-init.php
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Growing old is mandatory - Growing up is optional
Code Samples | People Counting System | Bits & Bobs
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-16-2009, 11:12 AM Re: Working with MSSQL in PHP
Super Talker

Posts: 102
Trades: 0
I've read them before I posted. I still couldn't figure it out. Sigh.
Aaron™ is offline
Reply With Quote
View Public Profile
 
Old 10-16-2009, 12:11 PM Re: Working with MSSQL in PHP
tripy's Avatar
Do not try this at home!

Posts: 3,176
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
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'SQLVARCHARfalsefalse15);
mssql_bind($stmt'@password''MySuperPwd'SQLVARCHARfalsefalse36);
mssql_bind($stmt'@birthday''19750330'SQLVARCHARfalsefalse120);
mssql_bind($stmt'@email''some@thing.com'SQLVARCHARfalsefalse120);

// 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..
tripy is online now
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 10-16-2009, 12:24 PM Re: Working with MSSQL in PHP
Super Talker

Posts: 102
Trades: 0
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'SQLVARCHARfalsefalse15); 



Everything is working fine, thank you.

Last edited by Aaron™; 10-16-2009 at 12:32 PM..
Aaron™ is offline
Reply With Quote
View Public Profile
 
Old 10-16-2009, 02:26 PM Re: Working with MSSQL in PHP
tripy's Avatar
Do not try this at home!

Posts: 3,176
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
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.
tripy is online now
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 10-16-2009, 10:05 PM Re: Working with MSSQL in PHP
Super Talker

Posts: 102
Trades: 0
Quote:
Everything is working fine, thank you.
dsadd
Aaron™ is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Working with MSSQL in PHP
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.13430 seconds with 13 queries