Hello Everyone!!

We are making on the project with PHP4 and MSSQL7. Everything is based on
NT4 platform.
Certainly, in this case we are operating by SQL stored procedures.

The question is..

I found some problems while extracting data from database over ODBC
which we need to use to make a bridge between PHP and MSSQL.

For example, we created a table with columns:

col_subj_id int
col_subj_owner_id int
col_subj_last_update timestamp(8)
col_subj_title varchar(512)
col_subj_content text(16)
col_subj_keywords varchar(256)
col_subj_secur int
col_subj_reg_page varchar(128)


Then I try to execute a stored procedure usp_get_subj:

Create Procedure usp_get_subj
        (
                @subj_id int
        )
As
SELECT  *
FROM tbl_subject
WHERE col_subj_id = @subj_id

RETURN

Well, everything is working in Query Analyzer and in ASP but not in
PHP...

If obviously to define the column names like:

SELECT
col_subj_id,
col_subj_owner_id,
col_subj_last_update,
col_subj_title,
col_subj_content,
col_subj_keywords,
col_subj_secur,
col_subj_reg_page
FROM tbl_subject
WHERE col_subj_id = @subj_id

it will not be working either...

But! If to order the columns in the query of the stored procedure by
data types like:

SELECT  col_subj_id, -- int
        col_subj_owner_id, -- int
        col_subj_secur, -- int
        col_subj_last_update, -- timestamp(8)
        col_subj_title, -- varchar(512)
        col_subj_reg_page, -- varchar(128)
        col_subj_keywords, -- varchar(2560
        col_subj_content -- text(16)
FROM tbl_subject
WHERE col_subj_id = @subj_id


everything will be working pretty good..


WHY?????????????

Do you have any ideas on this subject? ;-)

Hope to obtain help from your side..

Thank you in advance.

Mike

P.S.

The friend of mine who is ASP programmer just told me that there was such a
problem with the old versions of ODBC. I am not sure but I am afraid that
the PHP's  ODBC support is aimed on that old ODBC driver. Could anyone
advice me anything on this subject please?

<?php
 include ('config.inc');

 // script itself:

 $rs_gp = call_stored_procedure("usp_get_subj $QUERY_subj");
 while (fetch_row($rs_gp)) {
         $DB_home_text = get_field($rs_gp, "col_subj_content");
 }
 $rs_gp = "";
?>


<?php
 // config.inc

 // database settings
 $DB_dsn = "dsn_sundown";
 $DB_user = "sundown";
 $DB_pass = "";
 include ('database.php');
?>

<?php
 // database.inc

 // call the stored procedure
 function call_stored_procedure($query)
 {
         $conn = get_connection($GLOBALS["DB_dsn"], $GLOBALS["DB_user"],
$GLOBALS["DB_pass"]);
         $result = odbc_exec($conn, $query);
         return $result;
         odbc_close($conn);
 };

 // get the connection handle
 function get_connection($dsn, $user, $pass)
 {
        $GLOBALS["conn"] = odbc_connect($dsn, $user, $pass);
        return $GLOBALS["conn"];
 };

 // retrieve the row of data
 function fetch_row($rs)
 {
                return odbc_fetch_row($rs);
 };

 // retrieve the field of data
 function get_field($rs, $field)
 {

                if (!$rs)
                {
                        $res = "No data was returned..";
                }

                if ($rs)
                {

                        $res = odbc_result($rs, $field);
                        /*
                        $no_r = odbc_num_rows($rs);
                        $no_f = odbc_num_fields($rs);

                        for ($i=1; $i<=$no_f; $i++)
                        {
                                $fn = odbc_field_name ($rs, $i);
                                if ($fn == $field)
                                {
                                        $res = odbc_result($rs, $field);
                                        break;
                                }
                        }
                        */
                }
        return $res;
 };
?>


Michael Yevdokimov
Web developer
e-mail: [EMAIL PROTECTED]

--------------------------------
Globalocity B.V.
Tel.: +31 (0)70 312 2814
Fax.: +31 (0)70 312 2808
http://www.globalocity.com
e-mail: [EMAIL PROTECTED]
--------------------------------



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to