Page 1 of 1

Connect Mysql error, where?

Posted: Thu Dec 31, 2009 12:00 pm
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

Re: Connect Mysql error, where?

Posted: Thu Dec 31, 2009 12:14 pm
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?

Re: Connect Mysql error, where?

Posted: Thu Dec 31, 2009 12:32 pm
by MichaelR

Code: Select all

mysql_select_db('vendas', $mysql_id);
The database name comes before the connection resource.

Re: Connect Mysql error, where?

Posted: Thu Dec 31, 2009 12:35 pm
by mariolopes
Solved
Thank you for your help