Connecting to MySql

Alles, was PHP betrifft, kann hier besprochen werden.

Connecting to MySql

Postby Murph » 05. December 2008 18:32

Excuse me that i don't speak German. I have one question. I am trying to use MySql for the first time. I have the following:

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_close($con);
?>
But when i run it shows HTTP 500 Internal server error. I have XAMPP installed on my PC so it should allow me to run MySql. But the PHP program shows error. I have used the example from W3C PHP tutorials http://www.w3schools.com/PHP/php_mysql_connect.asp

Hope someone can help.

Kind Regards,
Murph
Murph
 
Posts: 17
Joined: 30. September 2008 18:51

Re: Connecting to MySql

Postby glitzi85 » 05. December 2008 18:50

Error 500 is not related to PHP (normally). Look inside this file:

xampp\apache\logs\error.log

there you will find the reason for this error.

glitzi
User avatar
glitzi85
 
Posts: 1920
Joined: 05. March 2004 23:26
Location: Dahoim

Re: Connecting to MySql

Postby Murph » 05. December 2008 21:09

Hi,
the log shows
[Fri Dec 05 17:10:19 2008] [error] [client 127.0.0.1] PHP Fatal error: Call to undefined function mysql_connect() in C:\\xampp\\htdocs\\testmysql.php on line 2

But surely mysql_connect() is a valid function. What could i be doing wrong. Hope you can help and thanks.

Murph
Murph
 
Posts: 17
Joined: 30. September 2008 18:51

Re: Connecting to MySql

Postby glitzi85 » 05. December 2008 21:27

Open this file:

Code: Select all
C:\xampp\apache\bin\php.ini


and search for this line:

Code: Select all
;extension=php_mysql.dll


then remove the ; at the beginning, save the file and restart your Apache Server. Then try again your script.

glitzi
User avatar
glitzi85
 
Posts: 1920
Joined: 05. March 2004 23:26
Location: Dahoim

Re: Connecting to MySql

Postby Murph » 06. December 2008 17:09

Hi thanks for reply.
It had no ; on front of that line in the file. So what can i do. Just to say i can connect to mdb database and it works fine.
I have for that:
<?php
$dbq = str_replace("/", "\\", $_SERVER["DOCUMENT_ROOT"]) . "Database3.mdb";
if (!file_exists($dbq)) { echo "<br />No such file as $dbq"; }

$db_connection = odbc_connect("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$dbq", "ADODB.Connection", "password", "SQL_CUR_USE_ODBC");

$result = odbc_tables($db_connection);

# query the users table for name and surname
$query = "SELECT name, surname FROM table";


# perform the query
$res = odbc_exec($db_connection,"SELECT * FROM table ORDER BY name DESC");


?>

I would like to learn MySql and hope i can connect to a database that way. Hope you can help. Thanks again.

Murph
Murph
 
Posts: 17
Joined: 30. September 2008 18:51

Re: Connecting to MySql

Postby Wiedmann » 06. December 2008 20:27

It had no ; on front of that line in the file.

Which "php.ini" is your PHP using?
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: Connecting to MySql

Postby Murph » 07. December 2008 13:21

I don't know. How do i find out. I only started to use PHP a while back. I downloaded the XAMPP from apachefriends.org.

Regards,
Murph
Murph
 
Posts: 17
Joined: 30. September 2008 18:51

Re: Connecting to MySql

Postby Wiedmann » 07. December 2008 14:15

I don't know. How do i find out.

e.g. with phpinfo() (loaded configuration file).
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: Connecting to MySql

Postby Murph » 08. December 2008 11:24

Hi. Thanks.
The info shows:
System Windows NT GERRY-PC 6.0 build 6001
Build Date May 2 2008 18:01:20
Configure Command cscript /nologo configure.js "--enable-snapshot-build" "--with-gd=shared" "--with-extra-includes=C:\Program Files (x86)\Microsoft SDK\Include;C:\PROGRA~2\MICROS~2\VC98\ATL\INCLUDE;C:\PROGRA~2\MICROS~2\VC98\INCLUDE;C:\PROGRA~2\MICROS~2\VC98\MFC\INCLUDE" "--with-extra-libs=C:\Program Files (x86)\Microsoft SDK\Lib;C:\PROGRA~2\MICROS~2\VC98\LIB;C:\PROGRA~2\MICROS~2\VC98\MFC\LIB"
Server API Apache 2.0 Handler
Virtual Directory Support enabled
Configuration File (php.ini) Path C:\Windows
Loaded Configuration File C:\Program Files\PHP\php.ini
PHP API 20041225
PHP Extension 20060613
Zend Extension 220060519
Debug Build no
Thread Safety enabled
Zend Memory Manager enabled
IPv6 Support enabled
Registered PHP Streams php, file, data, http, ftp, compress.zlib
Registered Stream Socket Transports tcp, udp
Registered Stream Filters convert.iconv.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, zlib.*

I would just like to say that i am using windows vista not windows NT. Maybe that is not important.

Hope you can help.
Murph
Murph
 
Posts: 17
Joined: 30. September 2008 18:51

Re: Connecting to MySql

Postby Murph » 08. December 2008 11:52

Hi,
I was just thinking. This php.ini file ( C:\Program Files\PHP\php.ini)
is a different one than the one in c:/xampp/apache/bin and it does not have the line extension=php_mysql.dll
but it is in c:/xampp/apache/bin
What do i do.

Regards,
Murph
Murph
 
Posts: 17
Joined: 30. September 2008 18:51

Re: Connecting to MySql

Postby Wiedmann » 08. December 2008 12:03

I was just thinking. This php.ini file ( C:\Program Files\PHP\php.ini)

You have an additional PHP installed on your pc?
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: Connecting to MySql

Postby Murph » 08. December 2008 14:52

I have. I installed it when i didn't know how to use XAMPP Php but i got advice how to run it so i use it now. Should i uninstall the other version of PHP.


Kind Regards,
Murph
Murph
 
Posts: 17
Joined: 30. September 2008 18:51

Re: Connecting to MySql

Postby Wiedmann » 08. December 2008 15:25

Should i uninstall the other version of PHP

XAMPP allready include PHP. So there is no need for an other PHP installation. (only confusion)
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: Connecting to MySql

Postby Murph » 08. December 2008 16:28

Thanks very much for your help.
Works now.

Kind Regards,
Murph
Murph
 
Posts: 17
Joined: 30. September 2008 18:51

Re: Connecting to MySql

Postby Murph » 08. December 2008 17:55

Hi,
just to say that it shows
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: YES) in C:\xampp\htdocs\mywebsite\indexMYSQL.php on line 126
Could not connect: Access denied for user 'root'@'localhost' (using password: YES)

The php is:
<?php
$con = mysql_connect("localhost","root","newpassword");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}if (mysql_query("CREATE DATABASE my_db",$con))
{
echo "Database created";
}
else
{
echo "Error creating database: " . mysql_error();
}mysql_close($con);



?>

I changed the password using the localhost/security but it won't allow me to connect.

I understand if you can't help anymore.

Murph
Murph
 
Posts: 17
Joined: 30. September 2008 18:51

Next

Return to PHP

Who is online

Users browsing this forum: No registered users and 7 guests