adodb php linux mssql select

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Bogdan Zagan
Forum Newbie
Posts: 7
Joined: Wed May 29, 2002 2:15 am
Location: Romania

adodb» php» linux» mssql» select

Post by Bogdan Zagan »

Issue
---------------------------------------------
The SELECT statement returns an empty string. Actualy I can count the records but can't see the values.

The INSERT statement works just fine
---------------------------------------------
Information
---------------------------------------------
» Linux RedHat 7.3
» Php 4.12
» MsSql server 7.0 on Win 2k
Php library contains sybase_ct.so, odbc.so and other libraries
---------------------------------------------
PHP Code
---------------------------------------------
<?php
require("./adodb/adodb.inc.php");
require("./Connections/sphinx1conn.php");
?><?php
$Recordset1=$sphinx1conn->Execute("SELECT * FROM dbo.trainer") or DIE($sphinx1conn->ErrorMsg());
$Recordset1_numRows=0;
$Recordset1__totalRows=$Recordset1->RecordCount();
?>
In the body I have:
<?php echo $Recordset1->Fields("trainer")?>
---------------------------------------------
Coclusion:
Microsoft SQL server sucks, even working with clasic .asp on win platform. Especially with text field.
But when you are migrating from one platform to another you need to find an intermediate solution in the migration period

10x
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

Okay..this might not work anymore, but when I was usin ADOdb, I had this same problem:

Switch

Code: Select all

&lt;?php echo $Recordset1-&gt;Fields("trainer")?&gt;
with this:

Code: Select all

&lt;?php echo $Recordset1-&gt;Fields("TRAINER")?&gt;
Let me know.
Bogdan Zagan
Forum Newbie
Posts: 7
Joined: Wed May 29, 2002 2:15 am
Location: Romania

Post by Bogdan Zagan »

Nope, didn't work, same problem

Code: Select all

<?php echo $Recordset1->Fields("TRAINER")?>
and with the

Code: Select all

<?php echo $Recordset1->Fields("trainer")?>
Still, if INSERT works fine, that means that I succeded in instaling the requested libraries to work with PHP ?

In phpinfo script is mentioned that I have MsSql support

Should I double check some config files ?
Bogdan Zagan
Forum Newbie
Posts: 7
Joined: Wed May 29, 2002 2:15 am
Location: Romania

Post by Bogdan Zagan »

Still, can u provide me a page with a sample using ADODB and Select ?

Maybe my code is not right, or How I wrote the conection string...(Macromedia DW did that actually)

I use fretds 0.52

Code: Select all

&lt;?php
/* FileName="Connection_php_direct.htm" "driver=sun.jdbc.odbc.JdbcOdbcDriver|url=jdbc:odbc:SPHINX1|uid=Copsintranet|pword=intranet" 
 Type="JDBC" 
 Catalog="" 
 Schema=""
 HTTP="false" 
*/
	if(!isset($PHP_SELF)){ 
		$PHP_SELF=getenv("SCRIPT_NAME"); 
	}
	if (!isset($QUERY_STRING)){
		$QUERY_STRING="";
	}
	if (!isset($REQUEST_URI)){
		$REQUEST_URI=$PHP_SELF;
	}
   $MM_sphinx1_HOSTNAME = "10.50.169.98";
   $MM_sphinx1_DBTYPE = "mssql";
   $MM_sphinx1_DATABASE = "CopsWeb";
   $MM_sphinx1_USERNAME = "Copsintranet";
   $MM_sphinx1_PASSWORD = "intranet";
   $QUB_Caching = false;
   ADOLoadCode($MM_sphinx1_DBTYPE);
   $sphinx1=&amp;ADONewConnection($MM_sphinx1_DBTYPE);
   if($MM_sphinx1_DBTYPE == "access" || $MM_sphinx1_DBTYPE == "odbc"){
   		$sphinx1-&gt;PConnect($MM_sphinx1_DATABASE, $MM_sphinx1_USERNAME,$MM_sphinx1_PASSWORD);
   } else if($MM_sphinx1_DBTYPE == "ibase") {
   		$sphinx1-&gt;PConnect($MM_sphinx1_HOSTNAME.":".$MM_sphinx1_DATABASE,$MM_sphinx1_USERNAME,$MM_sphinx1_PASSWORD);
   } else {
   		$sphinx1-&gt;PConnect($MM_sphinx1_HOSTNAME,$MM_sphinx1_USERNAME,$MM_sphinx1_PASSWORD,$MM_sphinx1_DATABASE);
   }
?&gt;
Bogdan Zagan
Forum Newbie
Posts: 7
Joined: Wed May 29, 2002 2:15 am
Location: Romania

The solution

Post by Bogdan Zagan »

Conclusion:
ADOdb and Linux (Apache, Php, Freetds) and MsSql is not working well. To retrieve the database fields you have to code the old fasion way !

Code: Select all

<?php 
  // connect to database server
  $db_conn = mssql_connect("10.50.169.98","copsintranet","intranet")
    or die( "<strong>ERROR: Connection to SPHINX1 failed</strong>" );

  // select database - only if we want to query another database than the default one
  mssql_select_db( "WebCops", $db_conn )
    or die( "<strong>ERROR: Selecting database failed</strong>" );

  // query the database
  $query_result = mssql_query( "SELECT trainer FROM trainer", $db_conn )
    or die( "<strong>ERROR: Query failed</strong>" );
  $daten = mssql_fetch_array($query_result); 
?>

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<?php echo $daten&#1111;"trainer"];  ?>
</body>
</html>
Post Reply