gladxml
asked on
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;D ATABASE=gt s;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()
?>
Parse error: syntax error, unexpected '}', expecting ',' or ';' in C:\xampp\htdocs\xampp\GTS\
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;D
// 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()
?>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
and ; are missing for the lines:
echo "test <br/>";
}
$rs->MoveNext();
?>
echo "test <br/>";
}
$rs->MoveNext();
?>
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.
while (!$rs->EOF)
{
echo "test <br/>";
}
$rs->MoveNext();
should be:
while (!$rs->EOF) {
echo "test <br/>";
$rs->MoveNext()
}
else you have an ifinitive loop.
ASKER
the code is now like this
<?
// ADO Connection description
$db ='DRIVER={MySQL ODBC 3.51 Driver;}SERVER=localhost;D ATABASE=gt s;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>Descript ion:</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
<?
// ADO Connection description
$db ='DRIVER={MySQL ODBC 3.51 Driver;}SERVER=localhost;D
// 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>Descript
Ok this this case the connection string mustlook like:
$db ='DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost;DATABASE= gts;UID=ro ot;PWD=; OPTION=35';
as steelseth12 first mentioned in his code.
$db ='DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost;DATABASE=
as steelseth12 first mentioned in his code.
ASKER
Thanks but I got it working by downloading the adodb for php then all works below is the working script...
<?
include('adodb/adodb.inc.p hp');
$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();
}
?>
<?
include('adodb/adodb.inc.p
$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();
}
?>
ASKER
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']->Valu e);
Is this the correct way to write the field values.
echo($rs->Fields['jobcurr_
Is this the correct way to write the field values.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
$db = 'DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;D
{ in double quotes have special menaings http://www.php.net/manual/en/language.types.string.php#language.types.string.parsing.complex