php script to access mysql

I had the below script that I get from the web but unfortunately the code does not work. The error that I am getting is

Parse error: syntax error, unexpected '}', expecting ',' or ';' in C:\xampp\htdocs\xampp\GTS\test2.php on line 16

Somehow it does not connect to the db. XAMPP is installed on my PC. What are the thing that I need to do or setup so that the below script will run on my PC.

<?
// ADO Connection description
$db = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=gts;UID=root;PWD=; OPTION=35";

// Create connection object
$conn = new COM("ADODB.Connection") or die("Cannot start ADO");

// Open the database
$conn->Open($db);

// Execute the query
$rs = $conn->Execute("SELECT * FROM lktbl_jobcurr_relevance WHERE jobcurr_isDisplayed=1 ORDER BY jobcurr_Order;");
while (!$rs->EOF)
{
echo "test <br/>"
}
$rs->MoveNext()
?>
LVL 15
gladxmlAsked:
Who is Participating?
 
hernst42Commented:
Guess not. Try just:
echo($rs->Fields['jobcurr_id']);

See docu http://phplens.com/lens/adodb/docs-adodb.htm#ex1
0
 
steelseth12Commented:
You are missing a ; on line 15 echo "test <br/>" it should be echo "test <br/>";

<?
// ADO Connection description
$db = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=gts;UID=root;PWD=; OPTION=35";

// Create connection object
$conn = new COM("ADODB.Connection") or die("Cannot start ADO");

// Open the database
$conn->Open($db);

// Execute the query
$rs = $conn->Execute("SELECT * FROM lktbl_jobcurr_relevance WHERE jobcurr_isDisplayed=1 ORDER BY jobcurr_Order;");
while (!$rs->EOF)
{
echo "test <br/>";
}
$rs->MoveNext()
?>
0
 
gamebitsCommented:
Change this

{MySQL ODBC 3.51 Driver};

for this

{MySQL ODBC 3.51 Driver;}
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
hernst42Commented:
use single quotes in this case:
$db = 'DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=gts;UID=root;PWD=; OPTION=35';

{ in double quotes have special menaings http://www.php.net/manual/en/language.types.string.php#language.types.string.parsing.complex

0
 
hernst42Commented:
and ; are missing for the lines:

echo "test <br/>";
}
$rs->MoveNext();
?>
0
 
hernst42Commented:
An here is also a logical error:

while (!$rs->EOF)
{
echo "test <br/>";
}
$rs->MoveNext();

should be:
while (!$rs->EOF) {
  echo "test <br/>";
  $rs->MoveNext()
}
else you have an ifinitive loop.
0
 
gladxmlAuthor Commented:
the code is now like this

<?
// ADO Connection description
$db ='DRIVER={MySQL ODBC 3.51 Driver;}SERVER=localhost;DATABASE=gts;UID=root;PWD=; OPTION=35';

// Create connection object
$conn = new COM("ADODB.Connection") or die("Cannot start ADO");

// Open the database
$conn->Open($db);

// Execute the query
$rs = $conn->Execute("SELECT * FROM lktbl_jobcurr_relevance WHERE jobcurr_isDisplayed=1 ORDER BY jobcurr_Order;");
while (!$rs->EOF)
{
echo "test <br/>";
}
$rs->MoveNext();
?>

and the error that I get now is


Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Microsoft OLE DB Service Components<br/><b>Description:</b> Format of the initialization string does not conform to the OLE DB specification.' in C:\xampp\htdocs\xampp\GTS\test2.php:9 Stack trace: #0 C:\xampp\htdocs\xampp\GTS\test2.php(9): com->Open('DRIVER={MySQL O...') #1 {main} thrown in C:\xampp\htdocs\xampp\GTS\test2.php on line 9
0
 
hernst42Commented:
Ok this this case the connection string mustlook like:
$db ='DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost;DATABASE=gts;UID=root;PWD=; OPTION=35';

as steelseth12 first mentioned in his code.
0
 
gladxmlAuthor Commented:
Thanks but I got it working by downloading the adodb for php then all works below is the working script...

<?
include('adodb/adodb.inc.php');
$DB = NewADOConnection('mysql');
$server = "localhost";
$user= "root";
$pwd = "";
$db = "gts";
$DB->Connect($server, $user, $pwd, $db);

$rs = $DB->Execute("SELECT * FROM lktbl_jobcurr_relevance WHERE jobcurr_isDisplayed=1 ORDER BY jobcurr_Order;");
while (!$rs->EOF)
{
echo "test <br/>";
$rs->MoveNext();
}
?>
0
 
gladxmlAuthor Commented:
But I have anoher problem when I try to write the field values it does not appear. I am currently using the below line to display the field values

echo($rs->Fields['jobcurr_id']->Value);

Is this the correct way to write the field values.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.