Forum Moderators: coopster
?php
include 'library/config.php';
include 'library/opendb.php';
$query="select database(), user()";
$result=mysql_query($query);
echo $result;
include 'library/closedb.php';
?>
but the output of this script is:
Resource id #5
any one can help please?
[edited by: shams at 3:27 am (utc) on May 15, 2007]
The reason being that in order to send a query to mysql, you must first connect to the server using mysql_connect [php.net]() where one of the arguments is the username. Secondly, before you can send a query, you must select a database using mysql_select_db [php.net](). Since both of these things must be done before you can send a query, you should already know who the current user is and what database they are using. I hope this makes sense. ;)
You cannot echo the result directly because it is not a string, it is of a result type. You must 'extract' the data from it using something like phparion has shown you. In this case, there should only be one row returned, however, so you will not need the loop:
$query="select database() AS `db`, user() AS `user`";
$result=mysql_query($query);
$row = [url=http://www.php.net/mysql-fetch-assoc]mysql_fetch_assoc[/url]($result);
echo 'database: '.$row['db'],'<p>';
echo 'user: '.$row['user'];
how i can print the output somtehing like this:
db_hsot => localhost
db_user => root
db_name => y2006
echo 'host: '.$db_host.'<p>';
echo 'user: '.$db_user.'<p>';
echo 'database: '.$db_name.'<p>';
Good luck :)
include 'library/config.php';
include 'library/opendb.php';
I bet you already have current database and username in one of the above files which you are including in this page then you can simply use them as variables because after inclusion they are the part of your code, why do you need to fetch current db and username again with some extra code?