Sign in to follow this  
dave

[web] PHP Problem

Recommended Posts

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

Share this post


Link to post
Share on other sites
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. :)

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

:)

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
I'm glad that helped.
And don't forget that MsSQL is not the same as MySQL :). And for a manual about PHP you can check it's manual at http://www.php.net/docs.php.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this