Connect Mysql error, where?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mariolopes
Forum Contributor
Posts: 102
Joined: Sun May 22, 2005 7:08 am

Connect Mysql error, where?

Post by mariolopes »

Please i'm newbie and i want to connect to a mysql database: here is my code:
<?php
/* conexão à base de dados vendas*/

$mysql_id = mysql_connect('localhost', 'curso', '123');

mysql_select_db($mysql_id, 'vendas');

if (!$mysql_id){
die ('ops erro');
}
if (!$mysql_select_db){
die ('erro no slee '.mysql_error());
}
?>
The result in my webbrowser is:
Warning: mysql_select_db() expects parameter 1 to be string, resource given in C:\xampp\xampp\htdocs\vendasphp\vendas.php on line 6
erro no slee

Why? What i'm doing wrong?
Thank you
mario
mariolopes
Forum Contributor
Posts: 102
Joined: Sun May 22, 2005 7:08 am

Re: Connect Mysql error, where?

Post by mariolopes »

Ok Guys I'm really a newbie. Here is the right code:
<?php
/* conexão à base de dados vendas*/

$mysql_id = mysql_connect('localhost', 'curso', '123');

mysql_select_db($mysql_id,'vendas');

if(!mysql_select_db('vendas',$mysql_id)){
die ('Erro'.mysql_error());
}

?>
But i get the warning
Warning: mysql_select_db() expects parameter 1 to be string, resource given in C:\xampp\xampp\htdocs\vendasphp\vendas.php on line 6
Why?
MichaelR
Forum Contributor
Posts: 148
Joined: Sat Jan 03, 2009 3:27 pm

Re: Connect Mysql error, where?

Post by MichaelR »

Code: Select all

mysql_select_db('vendas', $mysql_id);
The database name comes before the connection resource.
mariolopes
Forum Contributor
Posts: 102
Joined: Sun May 22, 2005 7:08 am

Re: Connect Mysql error, where?

Post by mariolopes »

Solved
Thank you for your help
Post Reply