Current location: Hot Scripts Forums » Programming Languages » PHP » PHP Can't select database


PHP Can't select database

Reply
  #1 (permalink)  
Old 08-17-03, 08:39 PM
EST EST is offline
Newbie Coder
 
Join Date: Aug 2003
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Can't select database

I got a problem when selecting database
This is the code that won't work
PHP Code:

$dbname 'databasename';


mysql_select_db($dbname); 
This code is works
PHP Code:



mysql_select_db
('databasename'); 
I don't know what the problem is, howcome if setup the variable for database's name it unable to select database? can someone tell he how to setup one?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 08-18-03, 01:01 AM
Caimin Caimin is offline
Newbie Coder
 
Join Date: Jul 2003
Location: Rome, Italy.
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Weird - is that the whole code, or is there something before or after it?
__________________
Caimin Jones
Freelance Flash, web + games developer
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 08-18-03, 09:47 AM
EST EST is offline
Newbie Coder
 
Join Date: Aug 2003
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
that's not the whole code, here is the complete one

PHP Code:

<?php

$dbhost 
'localhost'
$dbusername 'user'
$dbpassword 'password'
$dbname 'databasename'

//Connection Function
function db_connect()
{
   @ 
$db mysql_pconnect($dbhost$dbusername$dbpassword); 
   if (!
$db)
    {
      echo 
'Could not connect to database, Please try again later.';
      exit;
    }
   @ 
$select mysql_select_db('databasename');
   if (!
$select)
    {
      echo 
'Error: Cant select database.';
      exit;
    }
}
?>
some people said it should be like this
but i've tried it, still won't work

PHP Code:

mysql_select_db($dbname$db); 


and i call this from other script throught function db_connect()

Last edited by EST; 08-18-03 at 09:50 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 08-18-03, 01:00 PM
Ryan's Avatar
Ryan Ryan is offline
Coding Addict
 
Join Date: May 2003
Location: Virginia
Posts: 391
Thanks: 0
Thanked 8 Times in 3 Posts
This is the code I use to connect to databases:
PHP Code:

<?php

$db 
mysql_connect("serveraddy""username""password") or die(mysql_error());

mysql_select_db("dbname"$db) or die(mysql_error());
?>
__________________
Ryan Huff
iNET Interactive, LLC

http://www.inetinteractive.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 08-19-03, 11:14 AM
ealmiladi ealmiladi is offline
Newbie Coder
 
Join Date: Aug 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Dude....

PHP Code:

<?php

$dbhost 
'localhost'
$dbusername 'user'
$dbpassword 'password'
$dbname 'databasename'

//Connection Function
function db_connect()
{
   @ 
$db mysql_pconnect($dbhost$dbusername$dbpassword); 
   if (!
$db)
    {
      echo 
'Could not connect to database, Please try again later.';
      exit;
    }
   @ 
$select mysql_select_db('$dbname');
   if (!
$select)
    {
      echo 
'Error: Cant select database.';
      exit;
    }
}
?>
Try that.....
__________________
Eamon
Go-Veron.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 03:22 AM
PHPCode.Org - PHP Code Submission Database Dana General Advertisements 8 11-29-06 10:04 PM
error when creating database tables with php script spiroth10 PHP 4 01-06-04 04:59 PM
Share database over the Internet nitinkedia The Lounge 2 11-20-03 03:07 PM
Send sms via php and mysql database help meeeeee eggdesign PHP 2 10-03-03 01:29 AM


All times are GMT -5. The time now is 12:44 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.