[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

php script to access mysql

Posted on 2007-10-12
10
Medium Priority
?
264 Views
Last Modified: 2013-12-13
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()
?>
0
Comment
Question by:gladxml
10 Comments
 
LVL 20

Assisted Solution

by:steelseth12
steelseth12 earned 200 total points
ID: 20065157
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
 
LVL 28

Assisted Solution

by:gamebits
gamebits earned 200 total points
ID: 20065168
Change this

{MySQL ODBC 3.51 Driver};

for this

{MySQL ODBC 3.51 Driver;}
0
 
LVL 48

Expert Comment

by:hernst42
ID: 20065169
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 48

Expert Comment

by:hernst42
ID: 20065176
and ; are missing for the lines:

echo "test <br/>";
}
$rs->MoveNext();
?>
0
 
LVL 48

Expert Comment

by:hernst42
ID: 20065188
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
 
LVL 15

Author Comment

by:gladxml
ID: 20065314
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
 
LVL 48

Expert Comment

by:hernst42
ID: 20065391
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
 
LVL 15

Author Comment

by:gladxml
ID: 20065475
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
 
LVL 15

Author Comment

by:gladxml
ID: 20067123
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
 
LVL 48

Accepted Solution

by:
hernst42 earned 600 total points
ID: 20067522
Guess not. Try just:
echo($rs->Fields['jobcurr_id']);

See docu http://phplens.com/lens/adodb/docs-adodb.htm#ex1
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month18 days, 15 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question