PHP School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a PHP Expert!

Join 300,449 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,573 people online right now. Registration is fast and FREE... Join Now!




PHP

 

PHP, DSN Less Conection

itsys

1 Jul, 2009 - 01:13 AM
Post #1

New D.I.C Head
*

Joined: 8 Jun, 2009
Posts: 8

CODE
<?php

//create an instance of the  ADO connection object
$conn = new COM ("ADODB.Connection")
  or die("Cannot start ADO");

//define connection string, specify database driver
$connStr = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source= C:\\wamp\\www\\test1\\database\\directorydb.mdb";
  $conn->open($connStr); //Open the connection to the database

//declare the SQL statement that will query the database
$query = "SELECT Category FROM tblCategories";

//execute the SQL statement and return records
$rs = $conn->execute($query);

$num_columns = $rs->Fields->Count();
echo $num_columns . "<br>";

for ($i=0; $i < $num_columns; $i++) {
    $fld[$i] = $rs->Fields($i);
}

echo "<table>";

while (!$rs->EOF)  //carry on looping through while there are records
{
    echo "<tr>";
    for ($i=0; $i < $num_columns; $i++) {
        echo "<td>" . $fld[$i]->value . "</td>";
    }
    echo "</tr>";
    $rs->MoveNext(); //move on to the next record
}


echo "</table>";

//close the connection and recordset objects freeing up resources
$rs->Close();
$conn->Close();

$rs = null;
$conn = null;
?>


When the upload application. What changes data sourse path. Pls healp me

** Edit ** code.gif

User is offlineProfile CardPM
+Quote Post


noorahmad

RE: PHP

1 Jul, 2009 - 01:59 AM
Post #2

Webmaster
Group Icon

Joined: 12 Mar, 2009
Posts: 2,018



Thanked: 125 times
Dream Kudos: 1350
My Contributions
Simply Change Connection String
lets say i have my database in my website/database folder.
php

$path = $_SERVER['DOCUMENT_ROOT']."/mysite/database";
$connStr = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source= $path/directorydb.mdb";

User is online!Profile CardPM
+Quote Post

itsys

RE: PHP

1 Jul, 2009 - 02:34 AM
Post #3

New D.I.C Head
*

Joined: 8 Jun, 2009
Posts: 8

thanks,
User is offlineProfile CardPM
+Quote Post

noorahmad

RE: PHP

1 Jul, 2009 - 02:40 AM
Post #4

Webmaster
Group Icon

Joined: 12 Mar, 2009
Posts: 2,018



Thanked: 125 times
Dream Kudos: 1350
My Contributions
Your Welcome smile.gif.
User is online!Profile CardPM
+Quote Post

itsys

RE: PHP

1 Jul, 2009 - 02:48 AM
Post #5

New D.I.C Head
*

Joined: 8 Jun, 2009
Posts: 8

CODE

<?php include('inc_dbconn.php');?>
<?php
//declare the SQL statement that will query the database
$query = "SELECT * FROM tblCategories";
//execute the SQL statement and return records
$rs = $conn->execute($query);
$num_columns = $rs->Fields->Count();


?>

<table border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%">

CODE
             <?php
                $i=2;
                $count=2;
                while (!$rs->EOF)
                {
                ?>
                <tr>
                  <td><?php $fld[$i] = $rs->Fields("Category"); echo $fld[$i]->value;$rs->MoveNext(); ?></td>
                  <td><?php $fld[$i] = $rs->Fields("Category"); echo $fld[$i]->value;$rs->MoveNext(); ?></td>
                  <td><?php $fld[$i] = $rs->Fields("Category"); echo $fld[$i]->value;$rs->MoveNext(); ?></td>
                </tr>


                <tr>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                </tr>
                <?php
                }
                ?>
              </table>


I have create tabele tblCategories in field Category, Categorycode, SubCategory And SubCategory code. My requirment per category below 3 subcategory how can possible...........Pls helpe me

Pls see the http://bestonlinedir.com/ my requirment same type

This post has been edited by itsys: 1 Jul, 2009 - 03:08 AM
User is offlineProfile CardPM
+Quote Post

noorahmad

RE: PHP

1 Jul, 2009 - 02:57 AM
Post #6

Webmaster
Group Icon

Joined: 12 Mar, 2009
Posts: 2,018



Thanked: 125 times
Dream Kudos: 1350
My Contributions
code.gif
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 01:49AM

Live PHP Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month