PDA

View Full Version : CGI connection to mySQL


pyreneeen
4-18-02, 08:04 AM
Hello,

is there anybody who could provide me an cgi script (template) to connect to mysql?. I have been trying the following one during several days and I get always the same error message:" Access denied".Before running this script I have set up some tables in the server, so normally I would have to have access.

$database = "mydatabase";
$hostname = "localhost";
$port="3306";
$user = "myuserid";
$password = "mypassword";
$dbh = DBI->connect("DBI:mysql:$database:$hostname:$port",
$user, $password);

And the message that I am getting is:
Unable to execute SQL statement
DBD::mysql::st execute failed: Access denied for user: 'myuser@localhost' to database 'Mydatabase' at listresort.cgi line 15.

Thanks to everybody who could help me

Marc

Atomic-Design
4-19-02, 01:29 AM
I've memorized this:


<?php
$user = "username";
$pass = "password";
$db = "database_name";

$link = mysql_connect("localhost",$user,$pass);
if (!$link)
die("Couldn't connect to MySQL");

mysql_select_db($db,$link)
or die("Couldn't select $db: ".mysql_error());
print "MySQL successfull!<br>";

pyreneeen
4-19-02, 03:41 AM
thank you