| | |
Database function fail
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jun 2008
Posts: 29
Reputation:
Solved Threads: 0
PHP Syntax (Toggle Plain Text)
function fafaconnect($db_host, $db_user, $db_pass, $db_name) { @mysql_connect($db_host, $db_user, $db_pass); @mysql_select_db($db_name); } if ($link = @mysql_connect("localhost", "admin", "pass")) { echo "pass-"; } else { echo "fail-"; } if ($select = @mysql_select_db("zushee")) { echo "pass-"; } else { echo "fail-"; } if ($newlink = fafaconnect("localhost", "admin", "pass", "zushee")) { echo "pass"; } else { echo "fail"; }
This returns pass-pass-fail. Any ideas?
Last edited by grr; Oct 11th, 2009 at 10:04 pm.
0
#2 Oct 11th, 2009
From the PHP Documentation:
Try changing localhost to 127.0.0.1 and see if this fixes your problem. If not, try echo'ing mysql_error() instead of "fail" as this will give you more details as to why your connect call is failing.
•
•
•
•
Note: Whenever you specify "localhost" or "localhost:port" as server, the MySQL client library will override this and try to connect to a local socket (named pipe on Windows). If you want to use TCP/IP, use "127.0.0.1" instead of "localhost". If the MySQL client library tries to connect to the wrong local socket, you should set the correct path as Runtime Configuration in your PHP configuration and leave the server field blank.
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend. 0
#3 Oct 12th, 2009
I guess this have the second argument(connection) missing:
try something like this:
php Syntax (Toggle Plain Text)
mysql_select_db($db_name)
php Syntax (Toggle Plain Text)
$conn = mysql_connect($db_host, $db_user, $db_pass); mysql_select_db($db_name, $conn);
![]() |
Similar Threads
- Do I need to use strotime for making a birthday notification. (PHP)
- help to write a function (C)
- VB.NET Database Connection Problem (VB.NET)
- Problems retrieving from database (VB.NET)
- require urgent help to retrieve image from database (PHP)
- print function not working (C++)
- Transfer database from one linux sserver to another (Oracle)
- How to incorporate Database into C++ ? (C++)
Other Threads in the PHP Forum
- Previous Thread: Edit Contents with TinyMCE and PHP/MYSQL
- Next Thread: Export .php to pdf(with table)
Views: 220 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class clean cms code countingeverycharactersfromastring cron curl database date directory display download dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla jquery limit link login loop mail match menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select server sessions simple sms soap source space spam speed sql structure syntax system table tutorial update updates upload url validation validator variable video web xml youtube






