Database connection is showing - database

When I try to connect my database with "dbconnect.php", it is showing like this:
could not connect: Access denied for user 'zigmasta_ajas'#'127.0.0.1' (using password: YES)
Why does this happen? I don't know much about sql and php. My website is hosted. The host provides phpmyadmin and mysql database.I have created a database and a user using mysql wizard. I think all are going well. Then why does this error happen? Please help me in detail.
The following is php code I used. please check the code. Does this code contain errors?
<?php
$user_name="zigmasta_ajas";
$password="password";
$server="127.0.0.1";
$database="zigmasta_dbtest";
$db_handle=mysql_connect($server,$user_name,
$password);
if(!$db_handle)
{
die('could not connect:'.mysql_error());
}
echo'connected successfully';
$db_found=mysql_select_db($database);
if($db_found)
{
echo"database found";
}
else{
echo"database not found";
}
mysql_close($db_handle);
?>

Related

Showing an error like no user is found even i created the user in pgadmin

Here i am trying to create a new database and new role/user to that. I created the database called 'testing' now. And I assigned the role/user called 'precision' to that database.
But my site still showing an error like below:
/usr/local/lib/php/kohana-v.2.3.4/system/libraries/drivers/Database/Pgsql.php [48]:
pg_connect(): Unable to connect to PostgreSQL server: ERROR: No such user: precision
If i try the same with anyother database and user then it is working fine.
I am new for Pg-admin and PostgreSQL. Kindly help and let me know What i did wrong. Thanks in advance. :)

Connect external database in php

I am beginner in php as well Google-app engine. I have created a php webpage, I just need this to connect to external MySQL database to log user visit stats.
Under stats.php how can I include("config.php"); also in config.php how to connect:
<?php
// change these variables
$host=("example.com"); //host
$uname="abc";//MySQL username
$pass="Abc#123";//MySQL password
$db="stats"; //MySQL Database
//don't need to change
$con = mysql_connect($host,$uname,$pass);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($db, $con);
?>
When I run stats.php I am getting below error on appspot.com
Failed to connect to MySQL: Unable to find the socket transport "tcp" - did you forget to enable it when you configured PHP?
I have also confirmed connectivity to my server from outside host, port 3306 is also opened.
$ mysql -u webadmin –h (server ip) –p
I am not getting proper way to use fetch url, please help.
Thanks.
Unfortunately this won't work (yet). The reason is that the App Engine PHP runtime doesn't currently support sockets. Other App Engine runtimes (Python/Java/Go) support sockets, so it's a safe bet that it'll be added to PHP at some point in the future.
$host="example.com"; // should contain a valid host name or an ip address of the mysql server to which you want to connect
Nothing else needs to be changed, username and password only if required different. You have to make sure that the remote database does allow external connections for that username. Besides, you'd be better off using mysqli_* instead of old deprecated mysql_* extension for MySQL.
$link = mysqli_connect($host,$uname,$pass,$db) or die("Error " . mysqli_error($link));
And under stats.php you can simply include any code file the way you already mentioned:
<?php
include("config.php");
?>
$con = mysql_connect('your_my_sql_servername or IP Address', 'new_user_which_u_created', 'password');
if (!$con) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_select_db('sandsbtob',$con) or die ("could not open db".mysql_error());
and also firewall of the server must be set-up to enable incomming connections on port 3306
Hope this will help you

having issues with database on live server with codeigniter project

I am working on a project using codeigniter. I completed the login and registration coding and works fine on my local computer. But when I upload the files to live server then it gives me following error
A Database Error Occurred
Unable to select the specified database: zafarsal_membership
Filename: core/Loader.php
Line Number: 346
In database.php I have added correct information. And zafarsal_membership database does exist there but still it gives me this error. Could you please help me where am I making mistake?
I was getting the same error... just change the $db['default']['dbdriver'] = 'mysql';
to $db['default']['dbdriver'] = 'mysqli';
Here are the diferences between "mysql" and "mysqli":
Hope it helps you!
Here are the usual suspects:
Does the database user have read/write access to the database?
Did you select the right database driver?
Does your connection to the database succeed?
Are you running the same version of the database server locally and on your server?
In 90% of the cases, it's one of the above.

Why can't I connect to the Database with symfony's propel ORM?

I'm building the blog project example shown in the "definitive guide of symfony" (chapter 8: the model) on official webpage.
When i do operations that affects the database (like save();) in symfony, this message appears:
Unable to open PDO connection [wrapped: SQLSTATE[28000] [1045] Access denied for user 'root'#'localhost' (using password: NO)]
I tried to find errors in propel configuration files and nothing found. I just did what the guide says, nothing else. Maybe i need to create by command line the database or something like.
You need to properly configure databases.yml with a valid user and password for your MySQL server. Right now it's trying to connect as the root user with no password, and it appears that's not valid for your local MySQL configuration.

How do I catch a connection failure to a nonexistant Rose::DB database?

My Perl application uses Rose::DB, Rose::DB::Object (ORM) and Tk on Windows XP. I need to check whether the database connection information (host, port, database name, user, password) leads to a valid connection. If I call $db->connect and use e.g. a nonexistant host for testing, Rose::DB says:
DBI connect('dbname=my_db;host=192.168.70.85;port=5432','postgres',...) failed: could not connect to server: No route to host (0x00002751/10065)
How do I catch this and create a new message for my application? Is this a question about try/catch in general?
Thank you for your help!
A solution that seems to work so far was posted to me from John:
my $ok = eval { $db->connect };
if(!$ok || $#) { # Connection failed }

Resources