Page 1 of 1

unable to select database in php

PostPosted: 09. November 2006 20:34
by lskumar
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

PostPosted: 10. November 2006 20:50
by Dave_L
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.

thank you dave

PostPosted: 11. November 2006 17:53
by lskumar
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