[web] PHP Problem

Started by
11 comments, last by dave 18 years, 4 months ago
Hey, Write so i have started coding. Now what i am trying to do is simply connect to the sql server that i have on my own computer. So i tried this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Log In</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
$msqlDbLink = msql_connect( "DAVESCOMPUTER" );

//$sql = 'CREATE DATABASE `s` DEFAULT CHARACTER SET ascii COLLATE ascii_general_ci';
echo "hello1!";

if ( $msqlDbLink != FALSE )
{	
	echo "hello2!";
	msql_close( $msqlDbLink );
}

?>
</body>
</html>


Now the handle that is return is FALSE. Any ideas what the host address is supposed to look like, i have also tried 'localhost'. Thanks in advance. Dave
Advertisement
Here's how I call the method

$con = msql_connect();
msql_select_db("test_db", $con);

Cheers
Chris
CheersChris
What about designating the server?

Dave
The default server (used when you do not supply arguments) is 'localhost:3306'
Well in order to do what you want to you will need to connect to the server, and after that you will need to select a database.
You will need to use the function @mysql_connect which takes 3 parameters.

@mysql_connect( $hostip, $dbusername, $dbpassword );


That $hostip is your ip, if you are using it localy you will need to set it to hostname or 127.0.0.1 .

The $dbusername is your database username, the one you set on your mysql server, and $dbpassword is your database password, the same that you set on your mysql server (on install usualy).

After this you might want to make sure you connect to the server by doing:
$sqlconnect = @mysql_connect( $hostip, $dbusername, $dbpassword );if ( !$sqlconnect ){	die( mysql_error() );}


Hope this help. :)
Is MSQL the same as MySQL?
When i installed mysql with xampp i never set up a username and password, i was never prompted to. All attempts to connect have failed thus far.

Dave
No sorry, read it wrong but still it is almost the same thing.
MS SQL Server means Microsoft SQL Server and is microsoft's, and MySQL is a free open source one.

Instead of:
$sqlconnect = @mysql_connect( $hostip, $dbusername, $dbpassword );if ( !$sqlconnect ){	die( mysql_error() );}


You will need to to:
$sqlconnect = mssql_connect( $hostip, $dbusername, $dbpassword );

Where this time your $hostip should be "localhost:3306" if you have the default port, and $dbusername & $dbpassword work the same way, username and password for your mssql server.

Also i think you should check www.php.net their manual it has a lot of information about it's functions.

:)
Ah that be one problem sorted, MYSQL so they are changed to mysql_connect() etc now and i get this error:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\Program Files\xampp\htdocs\index.php on line 11
That means that you forgot to set the $dbpassword, and probably $dbusername.
Before those lines just do:
$dbusername = "root";$dbpassword = "";

If that does not work try your windows username/password.
I am not sure how to change the password after you install MySQL, when I installed mine I had the option to set username/password.

Hope this help :)

This topic is closed to new replies.

Advertisement