dbTalk Databases Forums  

Cant connect from PHP file to database

comp.databases.mysql comp.databases.mysql


Discuss Cant connect from PHP file to database in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Karl-Arne Gjersøyen
 
Posts: n/a

Default Cant connect from PHP file to database - 10-06-2010 , 07:39 AM






Hello again.
When I run this connect.php get and error.
The php file contains:
<?php
$dblink = mysql_connect("localhost","root","")or die("Kunne ikke koble
til database server");
$select_db = mysql_select_db("mac")or die("Kunne ikke velde database");

if(($dblink = true)and($select_db = true)){
echo "Du er koblet til og har valg database. Alt OK";
}
?>

But I get this error:

Warning: mysql_connect() [function.mysql-connect]: [2002] No such file
or directory (trying to connect via unix:///var/mysql/mysql.sock) in
/Users/karl/Sites/connect.php on line 2

Warning: mysql_connect() [function.mysql-connect]: No such file or
directory in /Users/karl/Sites/connect.php on line 2
Kunne ikke koble til database server

From terminal I get this result:
--------------------------------
Karl-Arne-Gjersyens-MacBook-Pro:Sites karl$ sudo /usr/local/mysql/bin/mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.6-rc MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input
statement.

mysql> SHOW DATABASES;
+--------------------+
Quote:
Database |
+--------------------+
information_schema |
mac |
mysql |
performance_schema |
test |
+--------------------+
5 rows in set (0.03 sec)

mysql>

What is wrong here?

Kind Regards,
Karl-Arne
--
My Home pages: http://www.karl-arne.name/

Reply With Quote
  #2  
Old   
Peter H. Coffin
 
Posts: n/a

Default Re: Cant connect from PHP file to database - 10-06-2010 , 10:55 AM






On Wed, 06 Oct 2010 14:39:56 +0200, Karl-Arne Gjersøyen wrote:
Quote:
Hello again.
When I run this connect.php get and error.
The php file contains:
?php
$dblink = mysql_connect("localhost","root","")or die("Kunne ikke koble
til database server");
$select_db = mysql_select_db("mac")or die("Kunne ikke velde database");

if(($dblink = true)and($select_db = true)){
echo "Du er koblet til og har valg database. Alt OK";
}
?

But I get this error:

Warning: mysql_connect() [function.mysql-connect]: [2002] No such file
or directory (trying to connect via unix:///var/mysql/mysql.sock) in
/Users/karl/Sites/connect.php on line 2

Warning: mysql_connect() [function.mysql-connect]: No such file or
directory in /Users/karl/Sites/connect.php on line 2
Kunne ikke koble til database server

From terminal I get this result:
--------------------------------
Karl-Arne-Gjersyens-MacBook-Pro:Sites karl$ sudo /usr/local/mysql/bin/mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.6-rc MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input
statement.

mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mac |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.03 sec)

mysql

What is wrong here?
You're using different mysql configurations for php and the CLI. The CLI
is correct. php has the wrong one. Fix php., by looking up what config
file the CLI is using and putting it in the php config.

--
76. If the hero runs up to my roof, I will not run up after him and
struggle with him in an attempt to push him over the edge. I will
also not engage him at the edge of a cliff. (In the middle of a
rope-bridge over a river of lava is not even worth considering.)

Reply With Quote
  #3  
Old   
Bill Braun
 
Posts: n/a

Default Re: Cant connect from PHP file to database - 10-06-2010 , 03:37 PM



On 10/6/2010 8:39 AM, Karl-Arne Gjersøyen wrote:
Quote:
Hello again.
When I run this connect.php get and error.
The php file contains:
?php
$dblink = mysql_connect("localhost","root","")or die("Kunne ikke koble
til database server");
$select_db = mysql_select_db("mac")or die("Kunne ikke velde database");

if(($dblink = true)and($select_db = true)){
echo "Du er koblet til og har valg database. Alt OK";
}
?

If that is literally what your script looks like it appears you have not
substituted the actual connect information. Are you using phpMyAdmin to
manage your database(s)? If so, load your database(s); the connect
information appears at the top of the page.

Bill B

Reply With Quote
  #4  
Old   
Erick T. Barkhuis
 
Posts: n/a

Default Re: Cant connect from PHP file to database - 10-07-2010 , 12:46 AM



Karl-Arne Gjersøyen:


Quote:
if(($dblink = true)and($select_db = true)){

What is wrong here?
A classical PHP programming error!
You are setting both to true instead of comparing.

I assume you want:
if ($dblink === true && $select_db === true) {



--
Erick

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.