Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php DSN-less connection trouble

Status
Not open for further replies.

jakeisstoked

Technical User
May 9, 2003
28
AU
Hi,
I'm trying to connet to a MySQL database using a dsn-less connection and I keep getting the following error:

Parse error, syntax_error, unexpected T_VARIABLE in C:\Inetpub\ on Line 10


This is how my connection looks:
********************************************
<?PHP
$conn = "DRIVER={MySQL};\
SERVER=localhost;\
DATABASE=test;\
USER=root;\
PASSWORD=xxx;\
OPTION=3;"

$conn->open($conn);

?>
********************************************

Is my code wrong?
-Jake
 
i'm not 100% sure but to use "$conn->open" $conn would have to be a class width the function open and the variables would have to be seperated width ",". it looks more like as asp-script and not php.

andreas owen
aowen@swissonline.ch
 
The parse error is due to the fact that the line which defines $conn is not ended with a semicolon:
Code:
<?PHP
    $conn = "DRIVER={MySQL};\     
             SERVER=localhost;\
             DATABASE=test;\
             USER=root;\
             PASSWORD=xxx;\
             OPTION=3;"[b][COLOR=red];[/color][/b]

    $conn->open($conn);
 
?>
 
<?PHP
$conn = "DRIVER={MySQL};\
SERVER=localhost;\
DATABASE=test;\
USER=root;\
PASSWORD=xxx;\
OPTION=3;";

$conn->open($conn);

?>

Thanks, I missed that, it has another error now:
"Fatal Error: Call to member function on a non-object in C:\Inetpub\ on Line 9", but I'm pretty sure it is to do with my PHP/MySQL setup, not the syntax. Thanks again.
 
$conn is not an object, it's a string.
Why do you want to connect to mysql this way from php ?
 
DSN-less connections arer a concept that comes from MS Excel, MS Query etc. It has nothing in common with the way how PHP connects to a MySQL server.
PHP needs something like this:
Code:
<?php
$host = 'localhost';
$user = 'myUser';
$pass = 'whateverPass';
$resourceLink = mysql_connect($host,$user,$pass) OR die("Cannot connect:".mysql_error());
# .. etc...

The fact that PHP runs on Windows Systems does not mean that MS program like connections can be made.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top