unable to select database in php

Problems with the Windows version of XAMPP, questions, comments, and anything related.

unable to select database in php

Postby lskumar » 09. November 2006 20:34

hello

1. installed xampp, apache, mysql
2. created database and tables
3. added rows to tables
4. able to login to mysql and phpmyadmin without any issues and
perform necessary operations on the database without any issues

in the php code, able to connect to the database
but unable to select the database

your help is much appreciated in advance.

got the error message as

<hr>
connect_host_name(localhost) connect_user_name(root) connect_pass_word(root) connect_data_base(LibraryDataBase)

26 Warning: mysql_select_db(): supplied argument is not a valid
MySQL-Link resource in
C:\Program Files\xampp\htdocs\lskxampp\mpl_web\mpl_include\mpl_database_connection_open.inc
on line 28
error: unable to select the database!:
<hr>

the code snippet is:

<hr>

<?php

include ("header.html");
include ("faq.html");

$connect_host_name = 'localhost:3306';
$connect_user_name = 'root';
$connect_pass_word = 'root';
$connect_data_base = 'LibraryDataBase';

echo "connect_host_name($connect_host_name) connect_user_name($connect_user_name) connect_pass_word($connect_pass_word) connect_data_base($connect_data_base)";

$connection_string = mysql_connect($connect_host_name, $connect_user_name, $connect_pass_word)
|| die ( "error: unable to connect to the database!:" . mysql_error() );

$db_select_string = mysql_select_db($connect_data_base, $connection_string)
//mysql_select_db('LibraryDataBase', $connection_string) ;
|| die ( "error: unable to select the database!: $connect_data_base " . mysql_error() );

//some more php code which does not get executed since
//the error unable to select the database is got

include ("header.html");
?>

<hr>

thank you
kumar
lskumar
 
Posts: 2
Joined: 09. November 2006 18:01

Postby Dave_L » 10. November 2006 20:50

Since "||" has higher precedence than "=", $connection_string is getting a boolean value, rather than a MySQL link identifier.

Change the "||" to "or" in both places.
User avatar
Dave_L
 
Posts: 212
Joined: 23. October 2004 00:43

thank you dave

Postby lskumar » 11. November 2006 17:53

hello dave

fantastic. this idea never occured to me.
this change apparently was what i had been searching for.
thank you so very much for your help.

regards
thank you
kumar
lskumar
 
Posts: 2
Joined: 09. November 2006 18:01


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 128 guests